Skip to content

Commit

Permalink
✅ Add test using faked-promise
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Jan 28, 2018
1 parent 1f596ef commit 3703431
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"codecov": "^3.0.0",
"eslint": "^4.16.0",
"eslint-config-posva": "^1.3.2",
"faked-promise": "^1.0.0",
"jest": "^22.1.4",
"vue": "^2.5.13",
"vue-jest": "^2.0.0",
Expand Down
25 changes: 18 additions & 7 deletions test/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { mount } from '@vue/test-utils'
import fakePromise from 'faked-promise'
import Helper from './utils/Helper'

const tick = () => new Promise(resolve => setImmediate(resolve))
const tick = () => new Promise(resolve => setTimeout(resolve, 0))

describe('Tweezing', () => {
let wrapper
let promise
beforeEach(() => {
promise = Promise.resolve('foo')
describe('Promised', () => {
let wrapper, promise, resolve, reject
beforeEach(async () => {
[promise, resolve, reject] = await fakePromise()
wrapper = mount(Helper, {
propsData: {
promise,
Expand All @@ -16,7 +16,18 @@ describe('Tweezing', () => {
})

test('displays a loading screen waiting for the promise', async () => {
expect(wrapper.text()).toBe('loading')
})

test('displays the resolved value once resolved', async () => {
resolve('foo')
await tick()
expect(wrapper.text()).toBe('foo')
})

test('displays an error if rejected', async () => {
reject(new Error('hello'))
await tick()
console.log(wrapper.text())
expect(wrapper.text()).toBe('hello')
})
})
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,10 @@ extsprintf@^1.2.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.4.0.tgz#e2689f8f356fad62cca65a3a91c5df5f9551692f"

faked-promise@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/faked-promise/-/faked-promise-1.0.0.tgz#5b7e93c422be46d9bdd1f8ae1293cb709ca352c0"

fast-deep-equal@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-1.0.0.tgz#96256a3bc975595eb36d82e9929d060d893439ff"
Expand Down

0 comments on commit 3703431

Please sign in to comment.