Use should

This commit is contained in:
Phan An 2017-12-11 00:54:37 +01:00
parent 77fdc4119f
commit aeefa21752
13 changed files with 38 additions and 69 deletions

View file

@ -2,8 +2,7 @@ import LoginForm from '@/components/auth/login-form.vue'
describe('components/auth/login-form', () => {
it('displays a form for users to log in', () => {
const wrapper = shallow(LoginForm)
expect(wrapper.findAll('form')).toHaveLength(1)
shallow(LoginForm).findAll('form').should.have.lengthOf(1)
})
it('triggers login method when form is submitted', () => {
@ -11,6 +10,6 @@ describe('components/auth/login-form', () => {
const wrapper = shallow(LoginForm)
wrapper.vm.login = spy
wrapper.find('form').trigger('submit')
expect(spy.called).toBe(true)
spy.called.should.be.true
})
})

View file

@ -5,12 +5,10 @@ import album from '@/tests/blobs/album'
describe('components/main-wrapper/extra/album-info', () => {
it('displays the info as a sidebar by default', () => {
const wrapper = shallow(AlbumInfo, {
propsData: {
album
}
propsData: { album }
})
expect(wrapper.findAll('#albumInfo.sidebar')).toHaveLength(1)
expect(wrapper.findAll('#albumInfo.full')).toHaveLength(0)
wrapper.findAll('#albumInfo.sidebar').should.have.lengthOf(1)
wrapper.findAll('#albumInfo.full').should.have.lengthOf(0)
})
it('can display the info in full mode', () => {
@ -20,27 +18,23 @@ describe('components/main-wrapper/extra/album-info', () => {
mode: 'full'
}
})
expect(wrapper.findAll('#albumInfo.sidebar')).toHaveLength(0)
expect(wrapper.findAll('#albumInfo.full')).toHaveLength(1)
wrapper.findAll('#albumInfo.sidebar').should.have.lengthOf(0)
wrapper.findAll('#albumInfo.full').should.have.lengthOf(1)
})
it('triggers showing full wiki', () => {
const wrapper = shallow(AlbumInfo, {
propsData: {
album
}
propsData: { album }
})
wrapper.find('.wiki button.more').trigger('click')
expect(wrapper.html()).toContain(album.info.wiki.full)
wrapper.html().should.contain(album.info.wiki.full)
})
it('lists the correct number of tracks', () => {
const wrapper = mount(AlbumInfo, {
propsData: {
album
}
propsData: { album }
})
expect(wrapper.findAll(TrackListItem)).toHaveLength(2)
wrapper.findAll(TrackListItem).should.have.lengthOf(2)
})
it('displays a message if the album has no info', () => {
@ -51,6 +45,6 @@ describe('components/main-wrapper/extra/album-info', () => {
album: albumWithNoInfo
}
})
expect(wrapper.html()).toContain('No album information found.')
wrapper.html().should.contain('No album information found.')
})
})

View file

@ -4,12 +4,10 @@ import artist from '@/tests/blobs/artist'
describe('components/main-wrapper/extra/artist-info', () => {
it('displays the info as a sidebar by default', () => {
const wrapper = shallow(ArtistInfo, {
propsData: {
artist
}
propsData: { artist }
})
expect(wrapper.findAll('#artistInfo.sidebar')).toHaveLength(1)
expect(wrapper.findAll('#artistInfo.full')).toHaveLength(0)
wrapper.findAll('#artistInfo.sidebar').should.have.lengthOf(1)
wrapper.findAll('#artistInfo.full').should.have.lengthOf(0)
})
it('can display the info in full mode', () => {
@ -19,18 +17,16 @@ describe('components/main-wrapper/extra/artist-info', () => {
mode: 'full'
}
})
expect(wrapper.findAll('#artistInfo.sidebar')).toHaveLength(0)
expect(wrapper.findAll('#artistInfo.full')).toHaveLength(1)
wrapper.findAll('#artistInfo.sidebar').should.have.lengthOf(0)
wrapper.findAll('#artistInfo.full').should.have.lengthOf(1)
})
it('triggers showing full bio', () => {
const wrapper = shallow(ArtistInfo, {
propsData: {
artist
}
propsData: { artist }
})
wrapper.find('.bio button.more').trigger('click')
expect(wrapper.html()).toContain(artist.info.bio.full)
wrapper.html().should.contain(artist.info.bio.full)
})
it('displays a message if the artist has no info', () => {
@ -41,6 +37,6 @@ describe('components/main-wrapper/extra/artist-info', () => {
artist: artistWithNoInfo
}
})
expect(wrapper.html()).toContain('Nothing can be found. This artist is a mystery.')
wrapper.html().should.contain('Nothing can be found. This artist is a mystery.')
})
})

View file

@ -9,17 +9,17 @@ import { event } from '@/utils'
describe('components/main-wrapper/extra/index', () => {
it('shows by default', () => {
const wrapper = shallow(ExtraSidebar)
expect(wrapper.findAll('#extra.showing')).toHaveLength(1)
wrapper.findAll('#extra.showing').should.have.lengthOf(1)
})
it('has a YouTube tab if using YouTube', () => {
const wrapper = shallow(ExtraSidebar)
expect(wrapper.findAll('.header .youtube')).toHaveLength(0)
wrapper.findAll('.header .youtube').should.have.lengthOf(0)
wrapper.setData({
sharedState: { useYouTube: true }
})
expect(wrapper.findAll('.header .youtube')).toHaveLength(1)
expect(wrapper.contains(YouTube)).toBe(true)
wrapper.findAll('.header .youtube').should.have.lengthOf(1)
wrapper.contains(YouTube).should.be.true
})
it('switches pane properly', () => {
@ -27,7 +27,7 @@ describe('components/main-wrapper/extra/index', () => {
expect(wrapper.find('.header .active').is('.lyrics')).toBe(true)
;['.artist', '.album', '.lyrics'].forEach(selector => {
wrapper.find(`.header ${selector}`).trigger('click')
expect(wrapper.find('.header .active').is(selector)).toBe(true)
wrapper.find('.header .active').is(selector).should.be.true
})
})
@ -38,7 +38,7 @@ describe('components/main-wrapper/extra/index', () => {
sharedState: { useYouTube: true }
})
;[ArtistInfo, AlbumInfo, Lyrics, YouTube].forEach(component => {
expect(wrapper.contains(component)).toBe(true)
wrapper.contains(component).should.be.true
})
})
@ -47,6 +47,6 @@ describe('components/main-wrapper/extra/index', () => {
const wrapper = shallow(ExtraSidebar)
wrapper.vm.fetchSongInfo = spy
event.emit('song:played', song)
expect(spy.calledWith(song)).toBe(true)
spy.calledWith(song).should.be.true
})
})

View file

@ -1,5 +1,3 @@
require('chai').should()
import localStorage from 'local-storage'
import { ls } from '../../services'
@ -28,8 +26,7 @@ describe('services/ls', () => {
it('correctly removes an item from local storage', () => {
localStorage('foo', 'bar')
ls.remove('foo')
var result = localStorage('foo') === null
result.should.be.true
;(localStorage('foo') === null).should.be.true
})
})
})

View file

@ -4,6 +4,8 @@ require('jsdom-global')()
// make sure polyfill is loaded before generators
require('babel-polyfill')
require('chai').should()
// make document and global available globally
const jsdom = require('jsdom')
const { JSDOM } = jsdom

View file

@ -1,6 +1,3 @@
require('chai').should()
import { cloneDeep, last } from 'lodash'
import { albumStore, artistStore } from '../../stores'
import data from '../blobs/data'
@ -8,8 +5,8 @@ const { artists, albums } = data
describe('stores/album', () => {
beforeEach(() => {
artistStore.init(cloneDeep(artists))
albumStore.init(cloneDeep(albums))
artistStore.init(_.cloneDeep(artists))
albumStore.init(_.cloneDeep(albums))
})
afterEach(() => {
@ -36,7 +33,7 @@ describe('stores/album', () => {
describe('#compact', () => {
it('correctly compacts albums', () => {
albumStore.compact()
albumStore.state.albums.length.should.equal(0)
albumStore.state.albums.should.be.empty
})
})

View file

@ -1,12 +1,9 @@
require('chai').should()
import { cloneDeep, last } from 'lodash'
import { artistStore } from '../../stores'
import data from '../blobs/data'
const artists = data.artists
describe('stores/artist', () => {
beforeEach(() => artistStore.init(cloneDeep(artists)))
beforeEach(() => artistStore.init(_.cloneDeep(artists)))
afterEach(() => artistStore.state.artists = [])
describe('#init', () => {
@ -26,7 +23,7 @@ describe('stores/artist', () => {
artistStore.compact()
// because we've not processed songs/albums, all artists here have no songs
// and should be removed after compact()ing
artistStore.state.artists.length.should.equal(0)
artistStore.state.artists.should.be.empty
})
})
})

View file

@ -1,5 +1,3 @@
require('chai').should()
import localStorage from 'local-storage'
import { preferenceStore } from '../../stores'

View file

@ -1,5 +1,3 @@
require('chai').should()
import { queueStore } from '../../stores'
import data from '../blobs/data'
@ -70,7 +68,7 @@ describe('stores/queue', () => {
describe('#clear', () => {
it('correctly clears all songs from queue', () => {
queueStore.clear()
queueStore.state.songs.length.should.equal(0)
queueStore.state.songs.should.be.empty
})
})
@ -92,8 +90,7 @@ describe('stores/queue', () => {
it('correctly returns null if at end of queue', () => {
queueStore.current = queueStore.state.songs[queueStore.state.songs.length - 1]
var result = queueStore.next === null
result.should.be.true
;(queueStore.next === null).should.be.true
})
})
@ -104,8 +101,7 @@ describe('stores/queue', () => {
it('correctly returns null if at end of queue', () => {
queueStore.current = queueStore.state.songs[0]
var result = queueStore.previous === null
result.should.be.true
;(queueStore.previous === null).should.be.true
})
})
})

View file

@ -1,6 +1,3 @@
require('chai').should()
import { cloneDeep, last } from 'lodash'
import { songStore, albumStore, artistStore, preferenceStore } from '../../stores'
import data from '../blobs/data'

View file

@ -1,5 +1,3 @@
require('chai').should()
import { userStore } from '../../stores'
import data from '../blobs/data'

View file

@ -1,5 +1,3 @@
require('chai').should()
import { secondsToHis, parseValidationError } from '../../utils'
describe('services/utils', () => {