Skip to content

Commit

Permalink
refs #53 Add integration tests for cancel, but it is skipped
Browse files Browse the repository at this point in the history
  • Loading branch information
h3poteto committed Aug 26, 2019
1 parent 6043fc4 commit ad94313
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@
"eslint-plugin-prettier": "^3.1.0",
"eslint-plugin-promise": "^4.1.1",
"eslint-plugin-standard": "^4.0.0",
"jest": "^24.8.0",
"jest-worker": "^24.9.0",
"lodash": "^4.17.14",
"prettier": "^1.17.1",
"jest": "^24.8.0",
"ts-jest": "^24.0.2",
"tslint": "^5.10.0",
"tslint-config-standard": "^7.0.0"
Expand Down
38 changes: 38 additions & 0 deletions test/integration/cancel.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import Mastodon from '@/mastodon'
import Worker from 'jest-worker'

jest.mock('axios', () => {
const mockAxios = jest.requireActual('axios')
mockAxios.get = (_path: string) => {
return new Promise(resolve => {
setTimeout(() => {
console.log('hoge')
resolve({
data: 'hoge',
status: 200,
statusText: '200OK',
headers: [],
config: {}
})
}, 5000)
})
}
return mockAxios
})

const worker = async (client: Mastodon) => {
const w: any = new Worker(require.resolve('./cancelWorker.ts'))
await w.cancel(client)
}

// Could not use jest-worker under typescript.
// I'm waiting for resolve this issue.
// https://github.com/facebook/jest/issues/8872
describe.skip('cancel', () => {
const client = new Mastodon('testToken', 'https://pleroma.io/api/v1')
it('should be raised', async () => {
const getPromise = client.get<{}>('/timelines/home')
worker(client)
await expect(getPromise).rejects.toThrow()
})
})
5 changes: 5 additions & 0 deletions test/integration/cancelWorker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Mastodon from '@/mastodon'

export function cancel(client: Mastodon) {
return client.cancel()
}
13 changes: 13 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2504,6 +2504,14 @@ jest-worker@^24.6.0:
merge-stream "^1.0.1"
supports-color "^6.1.0"

jest-worker@^24.9.0:
version "24.9.0"
resolved "https://registry.yarnpkg.com/jest-worker/-/jest-worker-24.9.0.tgz#5dbfdb5b2d322e98567898238a9697bcce67b3e5"
integrity sha512-51PE4haMSXcHohnSMdM42anbvZANYTqMrr52tVKPqqsPJMzoP6FYYDVqahX/HrAoKEKz3uUPzSvKs9A3qR4iVw==
dependencies:
merge-stream "^2.0.0"
supports-color "^6.1.0"

jest@^24.8.0:
version "24.8.0"
resolved "https://registry.yarnpkg.com/jest/-/jest-24.8.0.tgz#d5dff1984d0d1002196e9b7f12f75af1b2809081"
Expand Down Expand Up @@ -2776,6 +2784,11 @@ merge-stream@^1.0.1:
dependencies:
readable-stream "^2.0.1"

merge-stream@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60"
integrity sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==

micromatch@^3.1.10, micromatch@^3.1.4:
version "3.1.10"
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-3.1.10.tgz#70859bc95c9840952f359a068a3fc49f9ecfac23"
Expand Down

0 comments on commit ad94313

Please sign in to comment.