Update tests
This commit is contained in:
parent
3955b2e342
commit
05f0b399bf
41
tests/unit/components/FsExample.test.js
Normal file
41
tests/unit/components/FsExample.test.js
Normal file
@ -0,0 +1,41 @@
|
||||
import { shallowMount } from '@vue/test-utils';
|
||||
import FsExample from '@/components/FsExample.vue';
|
||||
|
||||
describe('FsExample.vue', () => {
|
||||
test('Render default contents', () => {
|
||||
const wrapper = shallowMount(FsExample);
|
||||
|
||||
expect(wrapper.html())
|
||||
.toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('Click button', () => {
|
||||
const wrapper = shallowMount(FsExample);
|
||||
let domButton = wrapper.find('[data-test="fs-example-button"]');
|
||||
domButton.trigger('click');
|
||||
|
||||
expect(window.nw.require)
|
||||
.toHaveBeenCalledWith('fs');
|
||||
|
||||
expect(wrapper.html())
|
||||
.toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('Error state', () => {
|
||||
window.nw.require.mockImplementation((module) => {
|
||||
if (module === 'fs') {
|
||||
return new Error();
|
||||
}
|
||||
});
|
||||
|
||||
const wrapper = shallowMount(FsExample);
|
||||
let domButton = wrapper.find('[data-test="fs-example-button"]');
|
||||
domButton.trigger('click');
|
||||
|
||||
expect(window.nw.require)
|
||||
.toHaveBeenCalledWith('fs');
|
||||
|
||||
expect(wrapper.html())
|
||||
.toMatchSnapshot();
|
||||
});
|
||||
});
|
43
tests/unit/components/__snapshots__/FsExample.test.js.snap
Normal file
43
tests/unit/components/__snapshots__/FsExample.test.js.snap
Normal file
@ -0,0 +1,43 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`FsExample.vue Click button 1`] = `
|
||||
<div>
|
||||
<!---->
|
||||
<button>
|
||||
Click for File System example
|
||||
</button>
|
||||
<p>
|
||||
The contents of the current working directory:
|
||||
</p>
|
||||
<div class="contents">
|
||||
<div class="file">
|
||||
example-file-1.ext
|
||||
</div>
|
||||
<div class="file">
|
||||
example-file-2.ext
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`FsExample.vue Error state 1`] = `
|
||||
<div>
|
||||
<div>
|
||||
There was an error attempting to read from the file system.
|
||||
</div>
|
||||
<button>
|
||||
Try again for File System example
|
||||
</button>
|
||||
<!---->
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`FsExample.vue Render default contents 1`] = `
|
||||
<div>
|
||||
<!---->
|
||||
<button>
|
||||
Click for File System example
|
||||
</button>
|
||||
<!---->
|
||||
</div>
|
||||
`;
|
@ -141,5 +141,13 @@ exports[`HelloWorld.vue Render default contents 1`] = `
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<hr>
|
||||
<div>
|
||||
<!---->
|
||||
<button>
|
||||
Click for File System example
|
||||
</button>
|
||||
<!---->
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
@ -33,6 +33,15 @@ global.beforeEach(() => {
|
||||
}
|
||||
};
|
||||
window.nw = {
|
||||
require: jest.fn((module) => {
|
||||
if (module === 'fs') {
|
||||
return {
|
||||
readdirSync: jest.fn(() => {
|
||||
return ['example-file-1.ext', 'example-file-2.ext'];
|
||||
})
|
||||
};
|
||||
}
|
||||
}),
|
||||
Shell: {
|
||||
openExternal: jest.fn()
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user