Skip to content

Commit

Permalink
Fix event-emitter test
Browse files Browse the repository at this point in the history
Has been broken since previous refactor
  • Loading branch information
qm3ster committed Mar 25, 2019
1 parent 16212b4 commit 4c2ea2b
Showing 1 changed file with 16 additions and 31 deletions.
47 changes: 16 additions & 31 deletions __test__/index.spec.js
Expand Up @@ -12,11 +12,7 @@ const classes = require('../classes');
const modules = require('../modules');
const errors = require('../errors');
const async = require('../async');
const {
parse,
stringify,
performAsyncTask: performAsyncTaskCB
} = require('../event-emitter');
const Emitter = require('../event-emitter/lib/emitter');
require('../word-counting');

describe('tests', () => {
Expand Down Expand Up @@ -98,31 +94,20 @@ describe('tests', () => {
expect(result).toMatchSnapshot();
});

it('should run event emitter', async () => {
const performAsyncTask = () =>
new Promise(resolve => {
performAsyncTaskCB((err, result) => {
resolve(result);
});
});

const fixture = {
a: 1,
b: {
c: [
2,
3,
{
d: '4'
}
]
}
};

expect(parse(JSON.stringify(fixture))).toMatchSnapshot();
expect(JSON.parse(stringify(fixture))).toMatchSnapshot();
expect(parse(stringify(fixture))).toMatchSnapshot();
const result = await performAsyncTask();
expect(result).toEqual(17);
it('should run event emitter', () => {
const e = new Emitter();
const spy = jest.fn();
e.on('tick', spy);
expect.assertions(2);
setTimeout(() => {
e.shutdown();
}, 1250);
return new Promise(resolve => {
setTimeout(() => {
expect(spy).toHaveBeenCalledTimes(2);
expect(spy).toHaveBeenLastCalledWith({ count: 1 });
resolve();
}, 1750);
});
});
});

0 comments on commit 4c2ea2b

Please sign in to comment.