Skip to content

Commit 23ecca2

Browse files
committed
* Made logs of test.spec.js more specific * Added temp.spec.js file and some tests for computed properties * Changed script to run tests to jest in package.json
1 parent c27a27c commit 23ecca2

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "1.0.0",
44
"main": "index.js",
55
"scripts": {
6-
"test": "jest"
6+
"jest": "jest"
77
},
88
"repository": "https://github.com/codebryo/vue-school-test-utils-base.git",
99
"author": "Roman Kuba <[email protected]>",

specs/temp.spec.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Temperature from '@/temprature'
2+
import { mount } from '@vue/test-utils'
3+
4+
describe('Computed Properties Tests', () => {
5+
test('celsius property', () => {
6+
//const wrapper = mount(Temperature);
7+
const {vm} = mount(Temperature);
8+
//expect(wrapper.vm.celsius).toBe(0);
9+
expect(vm.celsius).toBe(0);
10+
11+
//wrapper.setData({degrees: 23}); // Use setData() when you're testing a whole template, as templates get
12+
// updated async
13+
14+
//But when testing a computed property, it gets updated rt away, no async. So, the prop can be set and tested and
15+
// directly. Makes fcnal tests cleaner.
16+
//wrapper.vm.degrees = 23;
17+
vm.degrees = 23;
18+
//expect(wrapper.vm.celsius).toBe(23);
19+
expect(vm.celsius).toBe(23);
20+
});
21+
22+
test('fahrenheit property converted from celsius', () => {
23+
const {vm} = mount(Temperature);
24+
expect(vm.fahrenheit).toBe(32);
25+
26+
vm.degrees = 16;
27+
expect(vm.fahrenheit).toBe(60.8);
28+
})
29+
});

specs/test.spec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import ListComponent from '@/list.vue'
66
creates a Wrapper containing the mounted and rendered Vue component. */
77
it('should mount a vue TestComponent', () => {
88
const wrapper = mount(TestComponent);
9-
console.log(wrapper);
9+
console.log("TestComponent wrapper: " + wrapper);
1010
expect(wrapper.text()).toContain("Hello Test");
1111

1212
//Wrapper HTML function returns the entire component DOM node as a string. toMatchSnapshot() creates a snapshot
1313
// of the component in the __snapshots__ dir. To learn more about snapshots, check out Snapshot Testing with Jest
1414
// at Vue School, but this class is not free.
1515
//debugger;
1616
expect(wrapper.html()).toMatchSnapshot();
17-
console.log(wrapper.html());
17+
console.log("TestComponent wrapper html(): " + wrapper.html());
1818
expect(wrapper.html()).toContain("<h1>Hello Test</h1>");
1919
});
2020

@@ -26,7 +26,7 @@ it('should override the default value to say Hello to in the TestComponent', ()
2626
expect(wrapper.text()).toContain("Hello VueSchool");
2727

2828
expect(wrapper.html()).toMatchSnapshot();
29-
console.log(wrapper.html());
29+
console.log("Overriden TestComponent wrapper html(): " + wrapper.html());
3030
expect(wrapper.html()).toContain("<h1>Hello VueSchool</h1>");
3131
});
3232

0 commit comments

Comments
 (0)