Skip to content

Instantly share code, notes, and snippets.

@adoji92

adoji92/List.spec.js

Created Apr 28, 2018
Embed
What would you like to do?
import { shallow } from '@vue/test-utils';
import List from '../src/components/List.vue';
describe('List.vue', () => {
it('renders li for each item in props.items', () => {
const items = ['', ''];
const wrapper = shallow(List, {
propsData: { items },
});
expect(wrapper.findAll('li')).toHaveLength(items.length);
});
it('matches snapshot', () => {
const items = ['item 1', 'item 2'];
const wrapper = shallow(List, {
propsData: { items },
});
expect(wrapper.html()).toMatchSnapshot();
});
})
{
"status": "ok",
"value": [
{
"username": "adoji",
"email": "adoji92@gmail.com"
},
...
...
]
}
module.exports = {
'Demo test Google' : function (client) {
client
.url('http://google.no')
.pause(1000);
// expect element to be present in 1000ms
client.expect.element('body').to.be.present.before(1000);
// expect element <#lst-ib> to have css property 'display'
client.expect.element('#lst-ib').to.have.css('display');
// expect element to have attribute 'class' which contains text 'vasq'
client.expect.element('body').to.have.attribute('class').which.contains('vasq');
// expect element <#lst-ib> to be an input tag
client.expect.element('#lst-ib').to.be.an('input');
// expect element <#lst-ib> to be visible
client.expect.element('#lst-ib').to.be.visible;
client.end();
}
};
페이지에 들어가서
어떤 버튼을 누르고
어떤 엘리먼트 input[type=text] 를 선택해서
어떤 값을 입력하고
제출을 하면
어떤 화면이 떠야한다
import { SomeClass, SomeEnum } from 'some-class';
describe('SomeClass', () => {
const sc = SomeClass.getInstance();
test('getInstance should return not null object', () => {
expect(sc).toBeDefined();
});
test('just created instance has ready status', () => {
expect(sc.status).toEqual(SomeEnum.READY);
});
});
import { SomeClass2, SomeEnum2 } from 'some-class2';
import mockedResponse from './mocked_response.json';
jest.mock('axios');
describe('SomeClass2', () => {
const sc = SomeClass2.getInstance();
test('getUserInfo(5) should return array that contains 5 user objects', async () => {
axios.get.mockResolvedValue({ data: mockedResponse });
const res = await sc.getUserInfo(5);
expect(res.status.toLowerCase()).toBe('ok');
const userInfoList = res.data.value;
expect(userInfoList).toBeDefined();
expect(userInfoList.length).toBe(5);
const user = userInfoList[0];
expect(user.username.length).not.toBe(0);
expect(user.email.length).not.toBe(0);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment