Comments (5)
Hi! My thoughts are:
-
The guide is not meant to be bound to a specific library/testing framework. The examples are illustrated with Jasmine (because it's widely used & has a nice chainable syntax) but they could also had been written assuming the usage of Mocha, Tape, Jest, Sinon or any another library. The main ambition is to present some useful guidelines that can hopefully help developers to write better tests, regardless of the testing tools used.
-
I think the example you take produces a report that doesn't mean anything because the example itself doesn't mean much ;) But if we take something closer to a real case, we could have:
describe('the ads manager', () => {
it('should mark the ad as displayed', () => {
// const isAdDisplayed = ...;
expect(isAdDisplayed).toBe(true);
});
});
With a better description, the report starts to be more explicit. Also, the spec title does not have to mention the name of the variable, which is a low level detail in regards to the functionality tested. At the end, if something fails, the stack trace would be your best friend to fix the code, the report would not be sufficient.
from js-unit-testing-guide.
You make an interesting point, I mean there are a vast amount of different scenarios one could argue for or against. I guess I didn't do a great job of articulating my point; I merely wanted to stress the point that with since
you gain much better log messages than a simple "cannot call function of undefined".
It's like - yeah the describe-it notion works really well to describe what you're testing, but then it's also important to describe what you're expecting, or how you're expecting the what.
Like you might want to test if the ad manager displayed, and then you're expecting a property to be set. So have your "the ads manager should mark the ad as displayed", with an "isAdDisplayed property to be true". Extending the premise of "what", and "how". What being the describe-it, and the since being the how.
from js-unit-testing-guide.
Indeed, unless if the "how" is a technical detail, and/or subject to changes/refactoring. In the example, the one thing I need to be sure is that the ad manager does its job properly. If the "how" is really important, I would explicitly state it in the spec title ("it should set the isAdDisplayed variable to true").
from js-unit-testing-guide.
Do you mean "it should have the isAdDisplayed variable set to true"?
from js-unit-testing-guide.
...or something similar ;)
from js-unit-testing-guide.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from js-unit-testing-guide.