chore: testrunner's ".not" should print appropriate message (#2459)

When failing, the ".not" matchers should print their name
with ".not" prefix.
This commit is contained in:
Andrey Lushnikov 2018-04-26 11:13:22 -07:00 committed by GitHub
parent 9ae64f237c
commit 8a62b10fd0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View File

@ -37,13 +37,13 @@ class Expect {
this.not.not = this;
for (const matcherName of Object.keys(matchers)) {
const matcher = matchers[matcherName];
this[matcherName] = applyMatcher.bind(null, matcherName, matcher, false, value);
this.not[matcherName] = applyMatcher.bind(null, matcherName, matcher, true, value);
this[matcherName] = applyMatcher.bind(null, matcherName, matcher, false /* inverse */, value);
this.not[matcherName] = applyMatcher.bind(null, matcherName, matcher, true /* inverse */, value);
}
function applyMatcher(matcherName, matcher, inverse, value, ...args) {
const result = matcher.call(null, value, ...args);
const message = `expect.${matcherName} failed` + (result.message ? `: ${result.message}` : '');
const message = `expect.${inverse ? 'not.' : ''}${matcherName} failed` + (result.message ? `: ${result.message}` : '');
console.assert(result.pass !== inverse, message);
}
}

View File

@ -43,6 +43,9 @@ describe('testsuite', () => {
it('toContain', async (state) => {
expect('asdf').toContain('e');
});
it('not.toContain', async (state) => {
expect('asdf').not.toContain('a');
});
it('toEqual', async (state) => {
expect([1,2,3]).toEqual([1,2,3,4]);
});