style(tests): enforce it inside describe blocks

This commit is contained in:
MrTimscampi 2021-02-21 10:33:20 +01:00
parent c478dd548b
commit 33ad6f7982
12 changed files with 41 additions and 80 deletions

View File

@ -69,7 +69,10 @@ module.exports = {
'plugin:jest/recommended',
'plugin:jest/style',
'plugin:jest-formatting/strict'
]
],
rules: {
'jest/consistent-test-it': ['error']
}
}
]
};

View File

@ -32,7 +32,7 @@ const wrapper = mount(PlayButton, {
store
});
describe('PlayVutton', () => {
describe('PlayButton', () => {
it('shows the text "play"', (): void => {
expect(wrapper.text()).toBe('play');
});

View File

@ -13,7 +13,7 @@ beforeEach(() => {
});
describe('BlurhashCanvas', () => {
test('has a hash property of type String', () => {
it('has a hash property of type String', () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
expect(wrapper.vm.$options.props.hash).toBeDefined();
@ -22,7 +22,7 @@ describe('BlurhashCanvas', () => {
expect(wrapper.vm.$options.props.hash.type).toBe(String);
});
test('has a width property of type Number', () => {
it('has a width property of type Number', () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
expect(wrapper.vm.$options.props.width).toBeDefined();
@ -31,7 +31,7 @@ describe('BlurhashCanvas', () => {
expect(wrapper.vm.$options.props.width.type).toBe(Number);
});
test('has a height property of type Number', () => {
it('has a height property of type Number', () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
expect(wrapper.vm.$options.props.height).toBeDefined();
@ -40,7 +40,7 @@ describe('BlurhashCanvas', () => {
expect(wrapper.vm.$options.props.height.type).toBe(Number);
});
test('has a punch property of type Number', () => {
it('has a punch property of type Number', () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
expect(wrapper.vm.$options.props.punch).toBeDefined();
@ -49,18 +49,18 @@ describe('BlurhashCanvas', () => {
expect(wrapper.vm.$options.props.punch.type).toBe(Number);
});
test('requires a hash', () => {
it('requires a hash', () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
expect(wrapper.vm.$options.props.hash.required).toBeTruthy();
});
test('has a default width and height', () => {
it('has a default width and height', () => {
expect(wrapper.props().width).toBe(32);
expect(wrapper.props().height).toBe(32);
});
test('has a default punch', () => {
it('has a default punch', () => {
expect(wrapper.props().punch).toBe(1);
});
});

View File

@ -17,13 +17,13 @@ const wrapper = mount(SettingsPage, {
});
describe('SettingsPage', () => {
test('shows content, action and title if all are defined', () => {
it('shows content, action and title if all are defined', () => {
expect(wrapper.text()).toContain('test-page-title');
expect(wrapper.text()).toContain('This is a demo action');
expect(wrapper.text()).toContain('This is the demo content');
});
test('shows only the content if the title is undefined.', async () => {
it('shows only the content if the title is undefined.', async () => {
await wrapper.setProps({ pageTitle: undefined });
expect(wrapper.text()).toEqual(

View File

@ -1,42 +0,0 @@
import { mount } from '@vue/test-utils';
import SettingsPageTwoColumns from '~/components/Layout/SettingsPageTwoColumns.vue';
const $t = (str: string): string => str;
const wrapper = mount(SettingsPageTwoColumns, {
propsData: {
leftTitle: 'left-column-title',
rightTitle: 'right-column-title'
},
mocks: {
$t
},
slots: {
leftContent: '<p>Lorem Ipsum</p>',
rightContent: '<p>Dolor Sit Amet</p>'
}
});
describe('SettingsPageTwoColumns', () => {
test('shows content and title if the titles are defined', () => {
expect(wrapper.text()).toContain('test-page-title');
expect(wrapper.text()).toContain('test-page-title');
expect(wrapper.text()).toContain('Lorem Ipsum');
expect(wrapper.text()).toContain('Dolor Sit Amet');
});
test('shows only the content if the titles are undefined', async () => {
await wrapper.setProps({ leftTitle: undefined, rightTitle: undefined });
expect(wrapper.text()).toEqual(
expect.not.stringContaining('left-column-title')
);
expect(wrapper.text()).toEqual(
expect.not.stringContaining('right-column-title')
);
expect(wrapper.text()).toContain('Lorem Ipsum');
expect(wrapper.text()).toContain('Dolor Sit Amet');
});
});

View File

@ -22,7 +22,7 @@ const FORMS_EXPECTED_OUTPUT = [
];
describe('formsHelper', () => {
test('correctly itemizes the array of items', () => {
it('correctly itemizes the array of items', () => {
expect(TestComponent.getItemizedSelect(FORMS_TEST_INPUT)).toMatchObject(
FORMS_EXPECTED_OUTPUT
);

View File

@ -6,7 +6,7 @@ const TestComponent = new Vue({
});
describe('formsHelper', () => {
test('correctly sanitizes HTML', () => {
it('correctly sanitizes HTML', () => {
/*
NOTE: It is not our place to test if the library used is secure.
We just want to check if it's actually doing anything.

View File

@ -6,7 +6,7 @@ const TestComponent = new Vue({
});
describe('itemHelper', () => {
test('returns true if the item can be played', () => {
it('returns true if the item can be played', () => {
// TODO: Replace with BaseItemKind enum
expect(TestComponent.canPlay({ Type: 'AggregateFolder' })).toEqual(false);
expect(TestComponent.canPlay({ Type: 'Audio' })).toEqual(true);
@ -51,7 +51,7 @@ describe('itemHelper', () => {
expect(TestComponent.canPlay({})).toEqual(false);
});
test('returns true if the item can be resumed', () => {
it('returns true if the item can be resumed', () => {
expect(
TestComponent.canResume({ UserData: { PlaybackPositionTicks: 1 } })
).toEqual(true);

View File

@ -6,7 +6,7 @@ const TestComponent = new Vue({
});
describe('timeUtils', () => {
test('converts time from ms to ticks', () => {
it('converts time from ms to ticks', () => {
expect(TestComponent.ticksToMs(10000)).toEqual(1);
expect(TestComponent.ticksToMs(undefined)).toEqual(0);
@ -14,11 +14,11 @@ describe('timeUtils', () => {
expect(TestComponent.ticksToMs(null)).toEqual(0);
});
test('converts time from ticks to ms', () => {
it('converts time from ticks to ms', () => {
expect(TestComponent.msToTicks(1)).toEqual(10000);
});
test('formats time properly', () => {
it('formats time properly', () => {
expect(TestComponent.formatTime(5)).toEqual('0:05');
expect(TestComponent.formatTime(10)).toEqual('0:10');

View File

@ -32,7 +32,7 @@ beforeEach(() => {
});
describe('vuex: backdrop', () => {
test('sets the hash when "SET_CURRENT_BACKDROP" is committed', () => {
it('sets the hash when "SET_CURRENT_BACKDROP" is committed', () => {
store.replaceState({ ...defaultState() });
store.commit('SET_CURRENT_BACKDROP', BACKDROP_TEST_MUTATION);
@ -40,7 +40,7 @@ describe('vuex: backdrop', () => {
expect(store.state.blurhash).toBe(BACKDROP_SET_TEST_VALUE.blurhash);
});
test('sets the opacity when "SET_BACKDROP_OPACITY" is committed', () => {
it('sets the opacity when "SET_BACKDROP_OPACITY" is committed', () => {
store.replaceState({ ...defaultState() });
store.commit('SET_BACKDROP_OPACITY', BACKDROP_TEST_MUTATION);
@ -48,7 +48,7 @@ describe('vuex: backdrop', () => {
expect(store.state.opacity).toBe(1);
});
test('clears the hash when "CLEAR_CURRENT_BACKDROP" is committed', () => {
it('clears the hash when "CLEAR_CURRENT_BACKDROP" is committed', () => {
store.replaceState({ ...BACKDROP_SET_TEST_VALUE });
store.commit('CLEAR_CURRENT_BACKDROP');
@ -56,7 +56,7 @@ describe('vuex: backdrop', () => {
expect(store.state.blurhash).toBe('');
});
test('resets the opacity when "RESET_BACKDROP_OPACITY" is committed', () => {
it('resets the opacity when "RESET_BACKDROP_OPACITY" is committed', () => {
store.replaceState({ ...BACKDROP_SET_TEST_VALUE });
store.commit('RESET_BACKDROP_OPACITY');
@ -65,7 +65,7 @@ describe('vuex: backdrop', () => {
});
// Default case
test('sets the hash when setBackdrop is dispatched', () => {
it('sets the hash when setBackdrop is dispatched', () => {
// TODO: This should only test if the proper mutation is committed
store.replaceState({ ...defaultState() });
@ -75,7 +75,7 @@ describe('vuex: backdrop', () => {
});
// CASE B
test('clears the hash when clearBackdrop is dispatched', () => {
it('clears the hash when clearBackdrop is dispatched', () => {
// TODO: This should only test if the proper mutation is committed
store.replaceState({ ...BACKDROP_SET_TEST_VALUE });
@ -84,7 +84,7 @@ describe('vuex: backdrop', () => {
expect(store.state.blurhash).toBe('');
});
test('sets the opacity when setBackdropOpacity is dispatched', () => {
it('sets the opacity when setBackdropOpacity is dispatched', () => {
// TODO: This should only test if the proper mutation is committed
store.replaceState({ ...defaultState() });
@ -95,7 +95,7 @@ describe('vuex: backdrop', () => {
expect(store.state.opacity).toBe(BACKDROP_TEST_MUTATION.newOpacity);
});
test('resets the opacity when resetBackdropOpacity is dispatched', () => {
it('resets the opacity when resetBackdropOpacity is dispatched', () => {
// TODO: This should only test if the proper mutation is committed
store.replaceState({ ...BACKDROP_SET_TEST_VALUE });

View File

@ -28,7 +28,7 @@ beforeEach(() => {
});
describe('vuex: deviceProfile', () => {
test('sets the device profile when "SET_PROFILE" is committed', () => {
it('sets the device profile when "SET_PROFILE" is committed', () => {
store.replaceState({ ...defaultState() });
store.commit('SET_PROFILE', SET_DEVICE_PROFILE);
@ -36,7 +36,7 @@ describe('vuex: deviceProfile', () => {
expect(store.state).toMatchObject(SET_DEVICE_PROFILE);
});
test('clears the device profile when "CLEAR_PROFILE" is committed', () => {
it('clears the device profile when "CLEAR_PROFILE" is committed', () => {
store.replaceState({ ...SET_DEVICE_PROFILE });
store.commit('CLEAR_PROFILE');
@ -44,7 +44,7 @@ describe('vuex: deviceProfile', () => {
expect(store.state).toMatchObject(defaultState());
});
test('sets the device profile when setDeviceProfile is dispatched', () => {
it('sets the device profile when setDeviceProfile is dispatched', () => {
// TODO: This should only test if the proper mutation is committed
// Device profile may already be defined, this sets it to the default state
store.replaceState({ ...defaultState() });
@ -64,7 +64,7 @@ describe('vuex: deviceProfile', () => {
expect(store.state.clientVersion.length).toBeGreaterThan(1);
});
test('clears the device profile when clearDeviceProfile is dispatched', () => {
it('clears the device profile when clearDeviceProfile is dispatched', () => {
// TODO: This should only test if the proper mutation is committed
// Set test values to be cleared
store.replaceState({ ...SET_DEVICE_PROFILE });

View File

@ -21,7 +21,7 @@ beforeEach(() => {
});
describe('vuex: page', () => {
test('sets the title when "SET_PAGE_TITLE" is committed', () => {
it('sets the title when "SET_PAGE_TITLE" is committed', () => {
store.replaceState({ ...defaultState() });
store.commit('SET_PAGE_TITLE', { title: PAGE_SET_TEST_VALUE.title });
@ -29,7 +29,7 @@ describe('vuex: page', () => {
expect(store.state.title).toBe(PAGE_SET_TEST_VALUE.title);
});
test('sets the app bar opacity when "SET_APPBAR_OPACITY" is committed', () => {
it('sets the app bar opacity when "SET_APPBAR_OPACITY" is committed', () => {
store.replaceState({ ...defaultState() });
store.commit('SET_APPBAR_OPACITY', {
@ -39,7 +39,7 @@ describe('vuex: page', () => {
expect(store.state.opaqueAppBar).toBe(PAGE_SET_TEST_VALUE.opaqueAppBar);
});
test('sets the navigation drawer visibility when "SET_NAVDRAWER_VISIBILITY" is committed', () => {
it('sets the navigation drawer visibility when "SET_NAVDRAWER_VISIBILITY" is committed', () => {
store.replaceState({ ...defaultState() });
store.commit('SET_NAVDRAWER_VISIBILITY', {
@ -49,7 +49,7 @@ describe('vuex: page', () => {
expect(store.state.showNavDrawer).toBe(PAGE_SET_TEST_VALUE.showNavDrawer);
});
test('resets the state when "CLEAR_PAGE" is committed', () => {
it('resets the state when "CLEAR_PAGE" is committed', () => {
store.replaceState({ ...PAGE_SET_TEST_VALUE });
store.commit('CLEAR_PAGE');
@ -57,7 +57,7 @@ describe('vuex: page', () => {
expect(store.state).toMatchObject(defaultState());
});
test('sets the title when setPageTitle is dispatched', () => {
it('sets the title when setPageTitle is dispatched', () => {
// TODO: This should only test if the proper mutation is committed
store.replaceState({ ...defaultState() });
@ -66,7 +66,7 @@ describe('vuex: page', () => {
expect(store.state.title).toBe(PAGE_SET_TEST_VALUE.title);
});
test('sets the app bar opacity when setAppBarOpacity is dispatched', () => {
it('sets the app bar opacity when setAppBarOpacity is dispatched', () => {
// TODO: This should only test if the proper mutation is committed
store.replaceState({ ...defaultState() });
@ -77,7 +77,7 @@ describe('vuex: page', () => {
expect(store.state.opaqueAppBar).toBe(PAGE_SET_TEST_VALUE.opaqueAppBar);
});
test('sets the navigation drawer visibility when showNavDrawer is dispatched', () => {
it('sets the navigation drawer visibility when showNavDrawer is dispatched', () => {
// TODO: This should only test if the proper mutation is committed
store.replaceState({ ...defaultState() });
@ -88,7 +88,7 @@ describe('vuex: page', () => {
expect(store.state.showNavDrawer).toBe(PAGE_SET_TEST_VALUE.showNavDrawer);
});
test('resets the state when clearPage is dispatched', () => {
it('resets the state when clearPage is dispatched', () => {
// TODO: This should only test if the proper mutation is committed
store.replaceState({ ...PAGE_SET_TEST_VALUE });