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: +
+