refs #209 Add eslint config for jest spec codes

This commit is contained in:
AkiraFukushima 2018-12-29 00:21:26 +09:00
parent 473679be77
commit fb429e4926
6 changed files with 35 additions and 48 deletions

5
spec/.eslintrc Normal file
View File

@ -0,0 +1,5 @@
{
"env": {
"jest": true
}
}

View File

@ -29,17 +29,9 @@ describe('Login', () => {
}) })
describe('actions', () => { describe('actions', () => {
let state
beforeEach(() => {
state = {
instances: [],
selectedInstance: null,
searching: false
}
})
describe('fetchLogin', async () => { describe('fetchLogin', async () => {
const commitMock = jest.fn() const commitMock = jest.fn()
const url = await Login.actions.fetchLogin({ commit: commitMock }, 'pleroma.io') await Login.actions.fetchLogin({ commit: commitMock }, 'pleroma.io')
expect(ipcRenderer.send).toHaveBeenCalledWith('get-auth-url', 'pleroma.io') expect(ipcRenderer.send).toHaveBeenCalledWith('get-auth-url', 'pleroma.io')
}) })
describe('pageBack', () => { describe('pageBack', () => {

View File

@ -1,4 +1,3 @@
import assert from 'assert'
import emojify from '@/utils/emojify' import emojify from '@/utils/emojify'
describe('emojify', () => { describe('emojify', () => {
@ -20,18 +19,14 @@ describe('emojify', () => {
const str = 'I have a pen.' const str = 'I have a pen.'
it('should not change', () => { it('should not change', () => {
const result = emojify(str, emoji) const result = emojify(str, emoji)
assert.strictEqual( expect(result).toEqual(str)
result,
str
)
}) })
}) })
describe('Contain a shortcode', () => { describe('Contain a shortcode', () => {
const str = 'I like :python:' const str = 'I like :python:'
it('should replace', () => { it('should replace', () => {
const result = emojify(str, emoji) const result = emojify(str, emoji)
assert.strictEqual( expect(result).toEqual(
result,
'I like <img draggable="false" class="emojione" alt="python" title="python" src="https://example.com/python" />' 'I like <img draggable="false" class="emojione" alt="python" title="python" src="https://example.com/python" />'
) )
}) })
@ -40,8 +35,7 @@ describe('emojify', () => {
const str = 'I like :python: , :nodejs: and :slack:' const str = 'I like :python: , :nodejs: and :slack:'
it('should replace', () => { it('should replace', () => {
const result = emojify(str, emoji) const result = emojify(str, emoji)
assert.strictEqual( expect(result).toEqual(
result,
'I like <img draggable="false" class="emojione" alt="python" title="python" src="https://example.com/python" /> , <img draggable="false" class="emojione" alt="nodejs" title="nodejs" src="https://example.com/nodejs" /> and <img draggable="false" class="emojione" alt="slack" title="slack" src="https://example.com/slack" />' 'I like <img draggable="false" class="emojione" alt="python" title="python" src="https://example.com/python" /> , <img draggable="false" class="emojione" alt="nodejs" title="nodejs" src="https://example.com/nodejs" /> and <img draggable="false" class="emojione" alt="slack" title="slack" src="https://example.com/slack" />'
) )
}) })
@ -50,8 +44,7 @@ describe('emojify', () => {
const str = 'I like :python: , I love :python:' const str = 'I like :python: , I love :python:'
it('should replace', () => { it('should replace', () => {
const result = emojify(str, emoji) const result = emojify(str, emoji)
assert.strictEqual( expect(result).toEqual(
result,
'I like <img draggable="false" class="emojione" alt="python" title="python" src="https://example.com/python" /> , I love <img draggable="false" class="emojione" alt="python" title="python" src="https://example.com/python" />' 'I like <img draggable="false" class="emojione" alt="python" title="python" src="https://example.com/python" /> , I love <img draggable="false" class="emojione" alt="python" title="python" src="https://example.com/python" />'
) )
}) })

View File

@ -1,4 +1,3 @@
import assert from 'assert'
import suggestText from '@/utils/suggestText' import suggestText from '@/utils/suggestText'
describe('account', () => { describe('account', () => {
@ -6,40 +5,40 @@ describe('account', () => {
const str = '@h3pote' const str = '@h3pote'
it('should match', () => { it('should match', () => {
const [start, word] = suggestText(str, 7) const [start, word] = suggestText(str, 7)
assert.strictEqual(str, word) expect(str).toEqual(word)
assert.strictEqual(start, 1) expect(start).toEqual(1)
}) })
}) })
describe('Beginning of the sentence', () => { describe('Beginning of the sentence', () => {
const str = '@h3pote toot body' const str = '@h3pote toot body'
it('should match', () => { it('should match', () => {
const [start, word] = suggestText(str, 7) const [start, word] = suggestText(str, 7)
assert.strictEqual(word, '@h3pote') expect(word).toEqual('@h3pote')
assert.strictEqual(start, 1) expect(start).toEqual(1)
}) })
}) })
describe('Halfway of the sentence', () => { describe('Halfway of the sentence', () => {
const str = 'toot body @h3pote toot' const str = 'toot body @h3pote toot'
it('should match', () => { it('should match', () => {
const [start, word] = suggestText(str, 17) const [start, word] = suggestText(str, 17)
assert.strictEqual(word, '@h3pote') expect(word).toEqual('@h3pote')
assert.strictEqual(start, 11) expect(start).toEqual(11)
}) })
}) })
describe('End of the sentence', () => { describe('End of the sentence', () => {
const str = 'toot body @h3pote' const str = 'toot body @h3pote'
it('should match', () => { it('should match', () => {
const [start, word] = suggestText(str, 17) const [start, word] = suggestText(str, 17)
assert.strictEqual(word, '@h3pote') expect(word).toEqual('@h3pote')
assert.strictEqual(start, 11) expect(start).toEqual(11)
}) })
}) })
describe('No space', () => { describe('No space', () => {
const str = 'tootbody@h3pote' const str = 'tootbody@h3pote'
it('should not match', () => { it('should not match', () => {
const [start, word] = suggestText(str, 15) const [start, word] = suggestText(str, 15)
assert.strictEqual(word, null) expect(word).toEqual(null)
assert.strictEqual(start, null) expect(start).toEqual(null)
}) })
}) })
}) })

View File

@ -1,4 +1,3 @@
import assert from 'assert'
import { JSDOM } from 'jsdom' import { JSDOM } from 'jsdom'
import { findLink, findTag, findAccount } from '@/utils/tootParser' import { findLink, findTag, findAccount } from '@/utils/tootParser'
@ -16,7 +15,7 @@ I released Whalebird version 2.4.1. In version 2.4.0, Whalebird supports streami
const target = doc.getElementById('link') const target = doc.getElementById('link')
it('should find', () => { it('should find', () => {
const res = findLink(target) const res = findLink(target)
assert.strictEqual(res, 'https://github.com/h3poteto/whalebird-desktop/releases/tag/2.4.1') expect(res).toEqual('https://github.com/h3poteto/whalebird-desktop/releases/tag/2.4.1')
}) })
}) })
}) })
@ -34,7 +33,7 @@ I released Whalebird version 2.4.1. In version 2.4.0, Whalebird supports streami
const target = doc.getElementById('tag') const target = doc.getElementById('tag')
it('should find', () => { it('should find', () => {
const res = findTag(target) const res = findTag(target)
assert.strictEqual(res, 'whalebird') expect(res).toEqual('whalebird')
}) })
}) })
@ -50,7 +49,7 @@ I released Whalebird version 2.4.1. In version 2.4.0, Whalebird supports streami
const target = doc.getElementById('tag') const target = doc.getElementById('tag')
it('should find', () => { it('should find', () => {
const res = findTag(target) const res = findTag(target)
assert.strictEqual(res, 'whalebird') expect(res).toEqual('whalebird')
}) })
}) })
}) })
@ -67,8 +66,8 @@ describe('findAccount', () => {
const target = doc.getElementById('user') const target = doc.getElementById('user')
it('should find', () => { it('should find', () => {
const res = findAccount(target) const res = findAccount(target)
assert.strictEqual(res.username, '@h3_poteto') expect(res.username).toEqual('@h3_poteto')
assert.strictEqual(res.acct, '@h3_poteto@social.mikutter.hachune.net') expect(res.acct).toEqual('@h3_poteto@social.mikutter.hachune.net')
}) })
}) })
@ -82,8 +81,8 @@ describe('findAccount', () => {
const target = doc.getElementById('user') const target = doc.getElementById('user')
it('should find', () => { it('should find', () => {
const res = findAccount(target) const res = findAccount(target)
assert.strictEqual(res.username, '@h3poteto') expect(res.username).toEqual('@h3poteto')
assert.strictEqual(res.acct, '@h3poteto@pleroma.io') expect(res.acct).toEqual('@h3poteto@pleroma.io')
}) })
}) })
}) })

View File

@ -1,4 +1,3 @@
import assert from 'assert'
import { domainFormat } from '@/utils/validator' import { domainFormat } from '@/utils/validator'
describe('validator', () => { describe('validator', () => {
@ -7,56 +6,56 @@ describe('validator', () => {
const domain = 'https://mastodon.social' const domain = 'https://mastodon.social'
it('should not match', () => { it('should not match', () => {
const res = domain.search(domainFormat) const res = domain.search(domainFormat)
assert.strictEqual(res, -1) expect(res).toEqual(-1)
}) })
}) })
describe('string contains account name', () => { describe('string contains account name', () => {
const domain = 'h3_poteto@mastodon.social' const domain = 'h3_poteto@mastodon.social'
it('should not match', () => { it('should not match', () => {
const res = domain.search(domainFormat) const res = domain.search(domainFormat)
assert.strictEqual(res, -1) expect(res).toEqual(-1)
}) })
}) })
describe('string is gTLD domain', () => { describe('string is gTLD domain', () => {
const domain = 'mastodon.social' const domain = 'mastodon.social'
it('should match', () => { it('should match', () => {
const res = domain.search(domainFormat) const res = domain.search(domainFormat)
assert.strictEqual(res, 0) expect(res).toEqual(0)
}) })
}) })
describe('string is subdomain', () => { describe('string is subdomain', () => {
const domain = 'music.mastodon.social' const domain = 'music.mastodon.social'
it('should match', () => { it('should match', () => {
const res = domain.search(domainFormat) const res = domain.search(domainFormat)
assert.strictEqual(res, 0) expect(res).toEqual(0)
}) })
}) })
describe('string is subdomain', () => { describe('string is subdomain', () => {
const domain = 'social.tchncs.de' const domain = 'social.tchncs.de'
it('should match', () => { it('should match', () => {
const res = domain.search(domainFormat) const res = domain.search(domainFormat)
assert.strictEqual(res, 0) expect(res).toEqual(0)
}) })
}) })
describe('string is jp domain', () => { describe('string is jp domain', () => {
const domain = 'mstdn.co.jp' const domain = 'mstdn.co.jp'
it('should match', () => { it('should match', () => {
const res = domain.search(domainFormat) const res = domain.search(domainFormat)
assert.strictEqual(res, 0) expect(res).toEqual(0)
}) })
}) })
describe('string contains hyphone', () => { describe('string contains hyphone', () => {
const domain = 'music-mastodon.social' const domain = 'music-mastodon.social'
it('should match', () => { it('should match', () => {
const res = domain.search(domainFormat) const res = domain.search(domainFormat)
assert.strictEqual(res, 0) expect(res).toEqual(0)
}) })
}) })
describe('string is short domain', () => { describe('string is short domain', () => {
const domain = 'id.cc' const domain = 'id.cc'
it('should match', () => { it('should match', () => {
const res = domain.search(domainFormat) const res = domain.search(domainFormat)
assert.strictEqual(res, 0) expect(res).toEqual(0)
}) })
}) })
}) })