Last active
April 21, 2022 09:48
-
-
Save osher/51237ee8f74a7c18852799de9393bd48 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
This is a bad example: | |
*/ | |
const helper = require('./helper'); | |
const { user } = require('./fixture'); | |
const accounts = require('../lib/accounts'); | |
const Should = require('should'); | |
it('should work', async () => { | |
await Should(accounts.create(user.admin.registerData).be.rejected(); | |
await helper.accountCleared(user.noSuch.userName); | |
await accounts.create(user.noSuch.registerData); | |
await Should(accounts.create(user.noSuch.registerData).be.rejected(); | |
await accounts.close(user.noSuch.userName); | |
var created = await accounts.create(user.noSuch.registerData); | |
Should(created).have.properties(users.noSuch.profileData).have.properties(['id', 'salt', 'passwordSha']); | |
const stored = await helper.readAccount(user.noSuch.userName); | |
Object.assign(stored, { salt: 'mock-salt', passwordSha: 'mock-passwordSha' }); | |
Should(stored).deepEql(users.noSuch.expectedStoredForm); | |
}); | |
/** | |
It is a bad example because: | |
- it violates the holy-trinity-of-tests | |
- it mixes test intents AND employs case-sliding | |
- it does not organize by AAA | |
- when the scenario failed in the middle - it leaves a dirt (no aftermath) | |
- it does not assert anything above success/failure | |
- and when it does assert - it repeats exact operations that were done before | |
- seems to give a thought about code coverage, but it's still lacking | |
(see why in the better-example.test.js at https://gist.github.com/osher/4a08b0c633e41919298f0f6ce9357b92) | |
It still does right few things: | |
- separate out fixture data and test helper code out | |
- helper API is idempotent | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment