8000 feat (test): use the Vue wrapper created in nativescript-vue instead … · designemail/nativescript-vue@5ee5f96 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5ee5f96

Browse files
committed
feat (test): use the Vue wrapper created in nativescript-vue instead of the original Vue one
1 parent 953cb5d commit 5ee5f96

File tree

6 files changed

+30
-19
lines changed

6 files changed

+30
-19
lines changed

.babelrc

Lines changed: 0 additions & 9 deletions
This file was deleted.

jest.config.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
const { readFileSync } = require("fs")
2-
const babelConfig = JSON.parse(readFileSync("./.babelrc", "utf8"))
3-
4-
require("@babel/register")(babelConfig)
5-
61
const { join } = require("path")
72
const ROOT = process.cwd()
83
const TESTS = join(ROOT, "tests")
@@ -17,7 +12,8 @@ module.exports = {
1712
modulePaths: [
1813
"<rootDir>/platform/nativescript",
1914
"<rootDir>/node_modules/vue/src",
20-
"<rootDir>/node_modules/vue/src/platforms"
15+
"<rootDir>/node_modules/vue/src/platforms",
16+
"<rootDir>/tests"
2117
],
2218
collectCoverageFrom: [
2319
"platform/**/*.js",

tests/jest-setup.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ jest.mock('@nativescript/core/ui/layouts/layout-base', () => {
2929
}
3030
}
3131
}, {virtual: true})
32+
jest.mock('@nativescript/core/application', () => {
33+
return {
34+
Application() {
35+
}
36+
}
37+
}, {virtual: true})
38+
jest.mock('@nativescript/core/ui/frame', () => {
39+
const getComponentByName = require('register').getComponentByName
40+
const Frame = getComponentByName('Frame')
41+
42+
return {
43+
__esModule: true,
44+
default: Frame,
45+
}
46+
}, {virtual: true})
3247

3348
import { registerElement } from 'register'
3449
import Vue from 'vue'
@@ -41,9 +56,9 @@ Vue.config.ignoredElements = [
4156
'nativepage',
4257
'nativestacklayout',
4358
]
44-
4559
registerElement('Button', () => require('ns-ui-mocks/button').Button)
4660
registerElement('Label', () => require('ns-ui-mocks/label').Label)
4761
registerElement('Frame', () => require('ns-ui-mocks/frame').Frame)
4862
registerElement('Page', () => require('ns-ui-mocks/page').Page)
4963
registerElement('StackLayout', () => require('ns-ui-mocks/stacklayout').StackLayout)
64+
registerElement('Document', () => require('ns-ui-mocks/proxyviewcontainer').ProxyViewContainer)

tests/ns-ui-mocks/label.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
const NSComponent = require('./base')
32

43
class Label extends NSComponent {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const NSComponent = require('./base')
2+
3+
class ProxyViewContainer extends NSComponent {
4+
}
5+
6+
module.exports = {
7+
ProxyViewContainer
8+
}

tests/renderer/runtime/components/Button.spec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { mount } from '@vue/test-utils'
1+
import { createLocalVue, mount } from '@vue/test-utils'
22
import { getComponentByName } from 'register'
33

44
const Button = getComponentByName('Button')
@@ -30,7 +30,9 @@ const ButtonTest = {
3030
}
3131

3232
describe('Button', () => {
33-
const wrapper = mount(ButtonTest)
33+
const Vue = require('runtime').Vue
34+
const localVue = createLocalVue(Vue)
35+
const wrapper = mount(ButtonTest, { localVue })
3436

3537
it('renders the correct markup', () => {
3638
expect(wrapper.html()).toContain('<nativestacklayout>\n <nativelabel text="0"></nativelabel>\n <nativebutton>Increment</nativebutton>\n</nativestacklayout>')

0 commit comments

Comments
 (0)
0