Files
30-seconds-of-code/test/dig.test.js
Christian C. Salvadó 83a6a6ea32 [ENHANCEMENT] Properly configure eslint to work with jest (#988)
* chore: make aware eslint that we use jest

By setting up the jest environment, we no longer need to declare the
'test' global in the configuration.

* chore: don't need to import expect, it's a jest environment global

* chore: don't need to import expect when creating undefined test
2019-06-18 08:34:45 +03:00

32 lines
636 B
JavaScript

const {dig} = require('./_30s.js');
const data = {
level1: {
level2: {
level3: 'some data',
level3f: false,
level3a: [1, 2, 3, 4]
}
}
};
test('dig is a Function', () => {
expect(dig).toBeInstanceOf(Function);
});
test('Dig target success', () => {
expect(dig(data, 'level3')).toEqual('some data');
});
test('Dig target with falsey value', () => {
expect(dig(data, 'level3f')).toEqual(false);
});
test('Dig target with array', () => {
expect(dig(data, 'level3a')).toEqual([1, 2, 3, 4]);
});
test('Unknown target return undefined', () => {
expect(dig(data, 'level4')).toEqual(undefined);
});