Update tests

This commit is contained in:
The Jared Wilcurt 2019-10-29 12:27:18 -04:00
parent 3955b2e342
commit 05f0b399bf
4 changed files with 101 additions and 0 deletions

View 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();
});
});

View 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>
`;

View File

@ -141,5 +141,13 @@ exports[`HelloWorld.vue Render default contents 1`] = `
</a> </a>
</li> </li>
</ul> </ul>
<hr>
<div>
<!---->
<button>
Click for File System example
</button>
<!---->
</div>
</div> </div>
`; `;

View File

@ -33,6 +33,15 @@ global.beforeEach(() => {
} }
}; };
window.nw = { window.nw = {
require: jest.fn((module) => {
if (module === 'fs') {
return {
readdirSync: jest.fn(() => {
return ['example-file-1.ext', 'example-file-2.ext'];
})
};
}
}),
Shell: { Shell: {
openExternal: jest.fn() openExternal: jest.fn()
}, },