mawrkus / js-unit-testing-guide Goto Github PK
View Code? Open in Web Editor NEW๐ A guide to unit testing in Javascript
๐ A guide to unit testing in Javascript
If you take a look at this test case:
describe('A set of functionalities', () => {
it('should do something nice', () => {
expect(myVar).toBe(true);
});
});
if this test fails, then your report will say something along the lines of:
expected undefined to be true
which doesn't mean anything.
Would be much nicer to use Jasmine Custom Messages. Where your tests would start to look like this:
describe('A set of functionalities', () => {
it('should do something nice', () => {
since('i have a boolean variable named myVar with a value of true')
.expect(myVar).toBe(true);
});
});
And your typical report would read on a failure:
A set of functionalities should do something nice I have a boolean I have a boolean variable named myVar with a value of true FAILED
Basically creating much more approachable error reports that mean something later in the future. And motivating the notion of creating meaningful tests.
What are your thoughts?
It would be nice to have the guide translated in the following languages:
Thanks for the excellent guide.
It is unclear to me whether the examples are using mocha or jasmine, as both of them use describe()
. But I wanted to point out that mocha specifically discourages the use of arrow functions. https://mochajs.org/#arrow-functions
I think it would be helpful to make clear which framework/tooling the examples are using, and if they are indeed using mocha, they should perhaps use function()
instead. Thanks.
Now that the "๐ Resources" section has been splitted into different topics, it would be nice to populate it with more content. Blog posts, tutorials, videos, books, ... The idea is not to have an encyclopedia but to have a few (5 max. per topic?) high quality resources. Help, anyone?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.