Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert browser tests #645

Merged
merged 23 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
99aee20
Renemd (moved) test files
craigbeck Jul 2, 2024
b293fc7
Change test to use domTestRunner
craigbeck Jul 2, 2024
dddcef2
Change component.browser tests to use test harness app
craigbeck Jul 3, 2024
c06df7c
Merge branch 'master' of github.com:derbyjs/derby into convert-browse…
craigbeck Jul 3, 2024
107544e
Fix call of bound function
craigbeck Jul 3, 2024
7cd3c42
Add next tick wait before checking for removed properties
craigbeck Jul 3, 2024
7aaa5ad
Fix component tests to use harness.renderDom
craigbeck Jul 8, 2024
cec50ac
Fix test - call getFragment to render
craigbeck Jul 9, 2024
b011eea
Fix tests; ensure getFragment called torender page
craigbeck Jul 9, 2024
d453886
Skip custom markup on-destroy test; unknown why it does not call onDe…
craigbeck Jul 9, 2024
f1041fc
Update eslint config to allow es6 (Promise)
craigbeck Jul 9, 2024
9d2c2b8
Convertforms test to use jsdom
craigbeck Jul 9, 2024
44c93c8
Remove unused util.js
craigbeck Jul 9, 2024
2acfd62
Fix typo
craigbeck Jul 9, 2024
edadda8
Remove comment
craigbeck Jul 9, 2024
62531b6
Remove test use of this; use const and let over var
craigbeck Jul 9, 2024
512fdca
Use window from runner
craigbeck Jul 9, 2024
3e983b7
Change requires to imports
craigbeck Jul 9, 2024
3ad3105
Update node versions test matrix
craigbeck Jul 10, 2024
6d5b650
Revert "Change requires to imports"
craigbeck Jul 10, 2024
1cc37af
Fix window ref
craigbeck Jul 10, 2024
2dd2e0c
Use const/let over var
craigbeck Jul 10, 2024
5d2f6c1
Test matric to include next LTS v22
craigbeck Jul 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"env": {
"node": true
"node": true,
"es6": true
},
"parserOptions": {
"ecmaVersion": 5
"ecmaVersion": 9
},
"globals": {
"window": false,
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
strategy:
matrix:
node:
- 16
- 18
- 20
- 22
timeout-minutes: 10
steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion src/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export abstract class Component<T extends object = object> extends Controller<T>
});
return function componentBindWrapper(...args) {
if (!_fn) return;
return _fn.apply(_component, ...args);
return _fn.apply(_component, args);
};
}

Expand Down
6 changes: 0 additions & 6 deletions test/browser/util.js

This file was deleted.

74 changes: 37 additions & 37 deletions test/dom/ComponentHarness.mocha.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
var expect = require('chai').expect;
var Component = require('../../src/components').Component;
var domTestRunner = require('../../src/test-utils/domTestRunner');
const expect = require('chai').expect;
const Component = require('../../src/components').Component;
const domTestRunner = require('../../src/test-utils/domTestRunner');

describe('ComponentHarness', function() {
var runner = domTestRunner.install();
const runner = domTestRunner.install();

describe('renderDom', function() {
it('returns a page object', function() {
function Box() {}
Box.view = {is: 'box'};
var harness = runner.createHarness('<view is="box" />', Box);
var page = harness.renderDom();
const harness = runner.createHarness('<view is="box" />', Box);
const page = harness.renderDom();
expect(page).instanceof(harness.app.Page);
});

it('sets component property on returned object', function() {
function Box() {}
Box.view = {is: 'box'};
var box = runner.createHarness('<view is="box" />', Box).renderDom().component;
const box = runner.createHarness('<view is="box" />', Box).renderDom().component;
expect(box).instanceof(Box);
});

Expand All @@ -27,7 +27,7 @@ describe('ComponentHarness', function() {
is: 'box',
source: '<index:><div class="box"></div>'
};
var fragment = runner.createHarness('<view is="box" />', Box).renderDom().fragment;
const fragment = runner.createHarness('<view is="box" />', Box).renderDom().fragment;
expect(fragment).instanceof(runner.window.DocumentFragment);
expect(fragment).html('<div class="box"></div>');
});
Expand All @@ -49,7 +49,7 @@ describe('ComponentHarness', function() {
'<index:>' +
'<div class="clown"></div>'
};
var box = runner.createHarness('<view is="box" />', Box, Clown).renderDom().component;
const box = runner.createHarness('<view is="box" />', Box, Clown).renderDom().component;
expect(box.myClown).instanceof(Clown);
});

Expand All @@ -61,9 +61,9 @@ describe('ComponentHarness', function() {
'<index:>' +
'<div class="box {{if open}}open{{/if}}"></div>'
};
var page = runner.createHarness('<view is="box" />', Box).renderDom();
var fragment = page.fragment;
var component = page.component;
const page = runner.createHarness('<view is="box" />', Box).renderDom();
const fragment = page.fragment;
const component = page.component;
expect(fragment).html('<div class="box "></div>');
component.model.set('open', true);
expect(fragment).html('<div class="box open"></div>');
Expand All @@ -77,8 +77,8 @@ describe('ComponentHarness', function() {
'<index:>' +
'<div as="container" class="box {{if open}}open{{/if}}"></div>'
};
var component = runner.createHarness('<view is="box" />', Box).renderDom().component;
var container = component.container;
const component = runner.createHarness('<view is="box" />', Box).renderDom().component;
const container = component.container;
expect(container.className).equal('box ');
component.model.set('open', true);
expect(container.className).equal('box open');
Expand All @@ -96,9 +96,9 @@ describe('ComponentHarness', function() {
'{{/unless}}' +
'</div>'
};
var page = runner.createHarness('<view is="box" />', Box)
const page = runner.createHarness('<view is="box" />', Box)
.stubComponent('clown').renderDom();
var model = page.component.model;
const model = page.component.model;
expect(page.clown).instanceof(Component);
model.set('hideClown', true);
expect(page.clown).equal(undefined);
Expand All @@ -121,10 +121,10 @@ describe('ComponentHarness', function() {
'{{/if}}' +
'</div>'
};
var page = runner.createHarness('<view is="box" show-happy />', Box)
const page = runner.createHarness('<view is="box" show-happy />', Box)
.stubComponent({is: 'clown', asArray: 'clowns'}).renderDom();
var clowns = page.clowns;
var model = page.component.model;
const clowns = page.clowns;
const model = page.component.model;
expect(clowns.length).equal(1);
expect(clowns[0].model.get('expression')).equal('happy');
model.set('showSad', true);
Expand All @@ -146,7 +146,7 @@ describe('ComponentHarness', function() {
is: 'box',
source: '<index:><div class="box"></div>'
};
var harness = runner.createHarness('<view is="box" />', Box);
const harness = runner.createHarness('<view is="box" />', Box);
expect(harness).to.render();
});

Expand All @@ -156,7 +156,7 @@ describe('ComponentHarness', function() {
is: 'box',
source: '<index:><p><div></div></p>'
};
var harness = runner.createHarness('<view is="box" />', Box);
const harness = runner.createHarness('<view is="box" />', Box);
expect(harness).not.to.render();
});

Expand All @@ -166,7 +166,7 @@ describe('ComponentHarness', function() {
is: 'box',
source: '<index:><table><tr><td></td></tr></table>'
};
var harness = runner.createHarness('<view is="box" />', Box);
const harness = runner.createHarness('<view is="box" />', Box);
expect(harness).not.to.render();
});

Expand All @@ -176,7 +176,7 @@ describe('ComponentHarness', function() {
is: 'box',
source: '<index:><div class="box"></div>'
};
var harness = runner.createHarness('<view is="box" />', Box);
const harness = runner.createHarness('<view is="box" />', Box);
expect(harness).to.render('<div class="box"></div>');
});

Expand All @@ -186,14 +186,14 @@ describe('ComponentHarness', function() {
is: 'box',
source: '<index:><p><div></div></p>'
};
var harness = runner.createHarness('<view is="box" />', Box);
const harness = runner.createHarness('<view is="box" />', Box);
expect(harness).not.to.render('<p><div></div></p>');
});

it('passes with blank view', function() {
function Box() {}
Box.view = {is: 'box'};
var harness = runner.createHarness('<view is="box" />', Box);
const harness = runner.createHarness('<view is="box" />', Box);
expect(harness).to.render('');
});

Expand All @@ -206,12 +206,12 @@ describe('ComponentHarness', function() {
Box.prototype.create = function() {
this.boxElement.className = 'box-changed-in-create';
};
var harness = runner.createHarness('<view is="box" />', Box);
const harness = runner.createHarness('<view is="box" />', Box);
expect(harness).to.render('<div class="box"></div>');
});

it('works with HTML entities like &nbsp;', function() {
var harness = runner.createHarness('&lt;&nbsp;&quot;&gt;');
const harness = runner.createHarness('&lt;&nbsp;&quot;&gt;');
expect(harness).to.render();
expect(harness).to.render('&lt;&nbsp;"&gt;');
});
Expand All @@ -223,7 +223,7 @@ describe('ComponentHarness', function() {
source: '<index:><div class="box">{{greeting}}</div>'
};
Box.prototype.init = function() {
var initialName = this.model.scope('_page.initialName').get();
const initialName = this.model.scope('_page.initialName').get();
expect(initialName).to.equal('Spot');
this.model.set('name', initialName);
this.model.start('greeting', ['name'], function(name) {
Expand All @@ -233,7 +233,7 @@ describe('ComponentHarness', function() {
return 'Hello, ' + name;
});
};
var harness = runner.createHarness('<view is="box" />', Box);
const harness = runner.createHarness('<view is="box" />', Box);
// Have the test depend on state in `_page` to make sure it's not cleared
// between rendering passes in `.to.render`.
harness.model.set('_page.initialName', 'Spot');
Expand All @@ -244,15 +244,15 @@ describe('ComponentHarness', function() {

describe('fake app.history implementation', function() {
it('accepts url option', function() {
var renderUrl = '/box?size=123';
var expectedQueryParams = {size: '123'};
const renderUrl = '/box?size=123';
const expectedQueryParams = {size: '123'};

var harness = runner.createHarness(
const harness = runner.createHarness(
'url: {{$render.url}} | query: {{JSON.stringify($render.query)}}'
);
var expectedHtml = 'url: /box?size=123 | query: {"size":"123"}';
const expectedHtml = 'url: /box?size=123 | query: {"size":"123"}';

var page = harness.renderHtml({url: renderUrl});
const page = harness.renderHtml({url: renderUrl});
expectPageParams(page, renderUrl, expectedQueryParams);
expect(page.html).to.equal(expectedHtml);

Expand All @@ -262,14 +262,14 @@ describe('ComponentHarness', function() {
});

it('supports push(url) and replace(url)', function() {
var harness = runner.createHarness(
const harness = runner.createHarness(
'url: {{$render.url}} | query: {{JSON.stringify($render.query)}}'
);

var page = harness.renderDom();
const page = harness.renderDom();
expectPageParams(page, '', {});

var newUrl = '/box?size=123';
const newUrl = '/box?size=123';
harness.app.history.push(newUrl);
expectPageParams(page, newUrl, {size: '123'});
expect(page.fragment).html('url: /box?size=123 | query: {"size":"123"}');
Expand Down
Loading
Loading