Skip to content

Instantly share code, notes, and snippets.

@marcoemrich
Last active July 3, 2020 14:29
Show Gist options
  • Save marcoemrich/79ca4e65d7e80697af3a18b05224acd4 to your computer and use it in GitHub Desktop.
Save marcoemrich/79ca4e65d7e80697af3a18b05224acd4 to your computer and use it in GitHub Desktop.
JS-Testing: Assertion Examples
describe('greater than in obj', () => {
// is the second value of the obj greater than 5?
const obj = {value: [5, 4]};
// different Assertions/Expectations/Matcher Variants
it('jest equal', () => expect(obj.value[1] > 5).toBeTruthy());
it('jest greater', () => expect(obj.value[1]).toBeGreaterThan(5));
it('jest matchObject', () => expect(obj).toMatchObject({value: [5, 5]}));
it('unexpected satisfy', () =>
unexpect(obj, 'to satisfy', {value: [5, unexpect.it('to be greater than', 4)]})
);
it('power assert', () => assert(obj.value[1] > 5));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment