refactor: example

This commit is contained in:
Vasil Chimev
2019-11-18 11:15:20 +02:00
parent 8136302611
commit 791a056fdd
3 changed files with 133 additions and 34 deletions

View File

@@ -1,47 +1,40 @@
import { Builder, Label, Frame } from "@nativescript/core/ui";
import { navigateToModule } from "@nativescript/core/testing/ui-helper";
import { navigateToModule, asdf, render } from "@nativescript/core/testing/ui-helper";
import { assert } from "@nativescript/core/testing/tk-unit";
// function assert(test: any, message?: string) {
// if (!test) {
// throw new Error(message);
// }
// }
const snippet = `
<StackLayout id="stack">
<Label id="label" text="Label"></Label>
</StackLayout>`
describe("---> describe", function () {
it("---> snippet", function () {
const rootView = Builder.parse(snippet);
const label = <Label>rootView.getViewById("label");
// it("---> snippet", function (done) {
// const rootView = Builder.parse(snippet);
// const label = <Label>rootView.getViewById("label");
// const actualText = label.text;
// const expectedText = "Label";
// assert(actualText === expectedText, `Actual: ${actualText}, Expected: ${expectedText}`);
// done();
// });
// it("---> page", function () {
// const rootView = Builder.load("test-page");
// const label = <Label>rootView.getViewById("label");
// const actualText = label.text;
// const expectedText = "Test Page Stack Label";
// assert(actualText === expectedText, `Actual: ${actualText}, Expected: ${expectedText}`);
// });
it("---> navigate to module", () => {
const page = navigateToModule("test-module");
const label = page.getViewById("label");
const actualText = label.text;
const expectedText = "Labe";
assert(actualText === expectedText, `Actual: ${actualText}, Expected: ${expectedText}`);
});
it("---> page", function () {
const rootView = Builder.load("test-page");
const label = <Label>rootView.getViewById("label");
const actualText = label.text;
const expectedText = "Test Page Stack Labe";
assert(actualText === expectedText, `Actual: ${actualText}, Expected: ${expectedText}`);
});
it("---> module", function () {
navigateToModule("test-module");
const label = <Label>Frame.topmost().getViewById("label");
const actualText = label.text;
const expectedText = "42 taps lef";
const expectedText = "42 taps left";
assert(actualText === expectedText, `Actual: ${actualText}, Expected: ${expectedText}`);
});
});

View File

@@ -0,0 +1,101 @@
// import { Builder, Label, Frame } from "@nativescript/core/ui";
// import { navigateToModule, asdf, render } from "@nativescript/core/testing/ui-helper";
// import { assert } from "@nativescript/core/testing/tk-unit";
// // function assert(test: any, message?: string) {
// // if (!test) {
// // throw new Error(message);
// // }
// // }
// const snippet = `
// <StackLayout id="stack">
// <Label id="label" text="Label"></Label>
// </StackLayout>`
// // describe("---> describe", function () {
// // it("---> snippet", function (done) {
// // const rootView = Builder.parse(snippet);
// // const label = <Label>rootView.getViewById("label");
// // const actualText = label.text;
// // const expectedText = "Label";
// // assert(actualText === expectedText, `Actual: ${actualText}, Expected: ${expectedText}`);
// // done();
// // });
// // it("---> page", function () {
// // const rootView = Builder.load("test-page");
// // const label = <Label>rootView.getViewById("label");
// // const actualText = label.text;
// // const expectedText = "Test Page Stack Label";
// // assert(actualText === expectedText, `Actual: ${actualText}, Expected: ${expectedText}`);
// // });
// // it("---> module", function (done) {
// // // render done
// // asdf("test-module").then((fixture) => {
// // const label = fixture.getViewById("label");
// // const actualText = label.text;
// // const expectedText = "42 taps ";
// // assert(actualText === expectedText, `Actual: ${actualText}, Expected: ${expectedText}`);
// // done();
// // });//.finally(done);
// // });
// // it('resolves', (done) => {
// // const resolvingPromise = new Promise((resolve) => {
// // resolve('promiseresolved');
// // });
// // resolvingPromise.then((result) => {
// // expect(result).to.equal('promise resolved');
// // }).finally(done);
// // });
// // });
// const resolvingPromise = new Promise((resolve) =>
// resolve('promise resolved')
// );
// const rejectingPromise = new Promise((resolve, reject) =>
// reject(new Error('promise rejected'))
// );
// describe('async await', () => {
// // Output:
// it('asdf ', () => {
// // const result = await asdf("test-module");
// const page = navigateToModule("test-module");
// const label = page.getViewById("label");
// const actualText = label.text;
// const expectedText = "42 taps left";
// assert(actualText === expectedText, `Actual: ${actualText}, Expected: ${expectedText}`);
// // expect(result).to.equal('promise resolved');
// });
// // Output: ✓ assertion success
// it('assertion success', async () => {
// const result = await resolvingPromise;
// expect(result).to.equal('promise resolved');
// });
// // // Output: AssertionError: expected 'promise resolved' to equal 'i fail'
// // it('failing assertion', async () => {
// // const result = await resolvingPromise;
// // expect(result).to.equal('i fail');
// // });
// // // Output: Error: promise rejected
// // it('promise rejects', async () => {
// // const result = await rejectingPromise;
// // expect(result).to.equal('promise resolved');
// // });
// });

View File

@@ -1,4 +1,11 @@
module.exports = function (config) {
config.set({
client: {
mocha: {
timeout: 3000 // 3 seconds - upped from 2 seconds
}
}
});
const options = {
// base path that will be used to resolve all patterns (eg. files, exclude)
@@ -18,13 +25,11 @@ module.exports = function (config) {
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter