diff --git a/tests/unit/components/FsExample.test.js b/tests/unit/components/FsExample.test.js new file mode 100644 index 0000000..0b6004a --- /dev/null +++ b/tests/unit/components/FsExample.test.js @@ -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(); + }); +}); diff --git a/tests/unit/components/__snapshots__/FsExample.test.js.snap b/tests/unit/components/__snapshots__/FsExample.test.js.snap new file mode 100644 index 0000000..25effa6 --- /dev/null +++ b/tests/unit/components/__snapshots__/FsExample.test.js.snap @@ -0,0 +1,43 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`FsExample.vue Click button 1`] = ` +
+ + +

+ The contents of the current working directory: +

+
+
+ example-file-1.ext +
+
+ example-file-2.ext +
+
+
+`; + +exports[`FsExample.vue Error state 1`] = ` +
+
+ There was an error attempting to read from the file system. +
+ + +
+`; + +exports[`FsExample.vue Render default contents 1`] = ` +
+ + + +
+`; diff --git a/tests/unit/components/__snapshots__/HelloWorld.test.js.snap b/tests/unit/components/__snapshots__/HelloWorld.test.js.snap index aad5429..5da6d1d 100644 --- a/tests/unit/components/__snapshots__/HelloWorld.test.js.snap +++ b/tests/unit/components/__snapshots__/HelloWorld.test.js.snap @@ -141,5 +141,13 @@ exports[`HelloWorld.vue Render default contents 1`] = ` +
+
+ + + +
`; diff --git a/tests/unit/setup.js b/tests/unit/setup.js index e84b8fc..32a1e81 100644 --- a/tests/unit/setup.js +++ b/tests/unit/setup.js @@ -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() },