Skip to content

Commit

Permalink
added test for call without context resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
kanekotic committed Aug 29, 2018
1 parent 8453a3c commit d467da1
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion test/unit/web-threads-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import faker from 'faker'

describe('web threads should', () => {

test('call returns result', async () => {
test('call with context returns result', async () => {
let fakeResult = faker.random.uuid()
let fakeContext = {some: faker.random.uuid()}
const webWorkerMock = {
Expand All @@ -26,6 +26,24 @@ describe('web threads should', () => {
expect(params.context).toEqual(fakeContext)
})

test('call without context returns result', async () => {
let fakeResult = faker.random.uuid()
let fakeContext = {some: faker.random.uuid()}
const webWorkerMock = {
postMessage: () => {webWorkerMock.onmessage({data: [fakeResult,fakeContext]})},
}
global.Worker = jest.fn().mockImplementation(() => webWorkerMock)
global.URL = {createObjectURL: jest.fn()}
let params = {
fn: () => {return 2},
args: [2]
}
let result = execute(params)
result = await result
expect(result).toEqual(fakeResult)
expect(params.context).toBeUndefined()
})

test('call fails', async () => {
let params = {
error: true
Expand Down

0 comments on commit d467da1

Please sign in to comment.