Skip to content

Commit 9642cf8

Browse files
committed
Transform direct import of vue component for form input via jest config; fix remaining cloudauth test. Still chatty, but it passes; need to address deprecations down the road.
1 parent 10d456f commit 9642cf8

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

client/src/components/User/CloudAuth/CloudAuth.mocha.js renamed to client/src/components/User/CloudAuth/CloudAuth.test.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ describe("CloudAuth component", () => {
2929
beforeEach(async () => {
3030
const creds = listCredentials.map(Credential.create);
3131
stub = sinon.stub(mockSvc, "listCredentials").resolves(creds);
32-
/* https://github.com/vuejs/vue-test-utils/issues/829 for more info
33-
* regarding the sync option used here.
34-
*/
35-
wrapper = shallowMount(CloudAuth, { sync: false, localVue });
32+
const attachElement = document.createElement("div");
33+
if (document.body) {
34+
document.body.appendChild(attachElement);
35+
}
36+
37+
wrapper = shallowMount(CloudAuth, { localVue, attachTo: attachElement });
3638
await flushPromises();
3739
});
3840

@@ -44,10 +46,10 @@ describe("CloudAuth component", () => {
4446

4547
describe("initialization", () => {
4648
it("should render the initial list", () => {
47-
assert(wrapper);
48-
assert(wrapper.contains(CloudAuthItem));
49-
assert(wrapper.vm.items.length == 2);
50-
assert(wrapper.vm.filteredItems.length == 2);
49+
expect(wrapper).toBeTruthy();
50+
expect(wrapper.findComponent(CloudAuthItem).exists()).toBeTruthy();
51+
expect(wrapper.vm.items.length == 2).toBeTruthy();
52+
expect(wrapper.vm.filteredItems.length == 2).toBeTruthy();
5153
});
5254
});
5355

@@ -57,35 +59,35 @@ describe("CloudAuth component", () => {
5759

5860
wrapper.vm.filter = "aws";
5961
results = wrapper.vm.filteredItems;
60-
assert(wrapper.contains(CloudAuthItem));
61-
assert(results.length == 1, `Wrong number of items: ${results.length}`);
62+
expect(wrapper.findComponent(CloudAuthItem).exists()).toBeTruthy();
63+
expect(results.length == 1).toBeTruthy();
6264

6365
wrapper.vm.filter = "azure";
6466
results = wrapper.vm.filteredItems;
65-
assert(results.length == 1, `Wrong number of items: ${results.length}`);
67+
expect(results.length == 1).toBeTruthy();
6668

6769
wrapper.vm.filter = "";
6870
results = wrapper.vm.filteredItems;
69-
assert(results.length == 2, `Wrong number of items: ${results.length}`);
71+
expect(results.length == 2).toBeTruthy();
7072
});
7173
});
7274

7375
describe("create button", () => {
7476
it("clicking create button should add a blank key", () => {
7577
let results = wrapper.vm.filteredItems;
76-
assert(wrapper.contains(CloudAuthItem));
77-
assert(results.length == 2, `Wrong number of items: ${results.length}`);
78+
expect(wrapper.findComponent(CloudAuthItem).exists()).toBeTruthy();
79+
expect(results.length == 2).toBeTruthy();
7880

7981
const button = wrapper.find("button[name=createNewKey]");
80-
assert(button);
82+
expect(button).toBeTruthy();
8183
button.trigger("click");
8284

8385
results = wrapper.vm.filteredItems;
84-
assert(results.length == 3, `Wrong number of items: ${results.length}`);
86+
expect(results.length == 3).toBeTruthy();
8587

8688
const blank = results.find((i) => i.id == null);
87-
assert(blank, "missing blank key");
88-
assert(blank.id == null);
89+
expect(blank).toBeTruthy();
90+
expect(blank.id == null).toBeTruthy();
8991
});
9092
});
9193
});

client/tests/jest/jest.config.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ const path = require("path");
33
// For a detailed explanation regarding each configuration property, visit:
44
// https://jestjs.io/docs/en/configuration.html
55

6+
const modulesToTransform = ["bootstrap-vue/src/components/form-input"];
7+
68
module.exports = {
79
// All imported modules in your tests should be mocked automatically
810
// automock: false,
@@ -167,14 +169,13 @@ module.exports = {
167169

168170
// A map from regular expressions to paths to transformers
169171
transform: {
170-
"^.+\\.js$": "babel-jest",
172+
[`(${modulesToTransform}).+\\.js$`]: "vue-jest",
171173
".*\\.(vue)$": "vue-jest",
174+
"^.+\\.js$": "babel-jest",
172175
},
173176

174177
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
175-
// transformIgnorePatterns: [
176-
// "/node_modules/"
177-
// ],
178+
transformIgnorePatterns: [`/node_modules/(?!${modulesToTransform})`],
178179

179180
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
180181
// unmockedModulePathPatterns: undefined,

0 commit comments

Comments
 (0)