Skip to content

Commit

Permalink
Change test to use domTestRunner
Browse files Browse the repository at this point in the history
  • Loading branch information
craigbeck committed Jul 2, 2024
1 parent 99aee20 commit b293fc7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 25 deletions.
25 changes: 18 additions & 7 deletions test/dom/as.mocha.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
var expect = require('chai').expect;
var derby = require('./util').derby;
var domTestRunner = require('../../src/test-utils/domTestRunner');

describe('as', function() {
var runner = domTestRunner.install({
jsdomOptions: {
// solution for `SecurityError: localStorage is not available for opaque origins`
// Racer interfaces with localStorage and the `as-object` tests use `page.model`
// methods causing the SecurityError if `url` is not set. Does not appear to impact
// `as-array` tests even though they also use `pae.model` methods so 🤷
url: 'http://localhost/'
}
});

it('HTML element `as` property', function() {
var app = derby.createApp();
const { app } = runner.createHarness();
app.views.register('Body', '<div as="nested[0]"></div>');
var page = app.createPage();
var fragment = page.getFragment('Body');
Expand All @@ -12,7 +22,7 @@ describe('as', function() {
});

it('Component `as` property', function() {
var app = derby.createApp();
const { app } = runner.createHarness();
app.views.register('Body', '<view is="item" as="nested[0]"></view>');
app.views.register('item', '<div></div>')
function Item() {};
Expand All @@ -25,7 +35,7 @@ describe('as', function() {
});

it('HTML element `as-object` property', function() {
var app = derby.createApp();
const { app } = runner.createHarness();
app.views.register('Body',
'<ul>' +
'{{each _page.items}}' +
Expand Down Expand Up @@ -66,7 +76,7 @@ describe('as', function() {
});

it('Component `as-object` property', function() {
var app = derby.createApp();
const { app } = runner.createHarness();
app.views.register('Body',
'<ul>' +
'{{each _page.items}}' +
Expand Down Expand Up @@ -115,12 +125,13 @@ describe('as', function() {
expect(fragment).html('<ul><li>D</li><li>A</li><li>C</li></ul>');

page.model.del('_page.items');
console.log('_page.items', items.get());

Check failure on line 128 in test/dom/as.mocha.js

View workflow job for this annotation

GitHub Actions / Node 16

'items' is not defined

Check failure on line 128 in test/dom/as.mocha.js

View workflow job for this annotation

GitHub Actions / Node 18

'items' is not defined

Check failure on line 128 in test/dom/as.mocha.js

View workflow job for this annotation

GitHub Actions / Node 20

'items' is not defined
expect(page.nested.map).eql({});
expect(fragment).html('<ul></ul>');
});

it('HTML element `as-array` property', function() {
var app = derby.createApp();
const { app } = runner.createHarness();
app.views.register('Body',
'<ul>' +
'{{each _page.items}}' +
Expand Down Expand Up @@ -162,7 +173,7 @@ describe('as', function() {
});

it('Component `as-array` property', function() {
var app = derby.createApp();
const { app } = runner.createHarness();
app.views.register('Body',
'<ul>' +
'{{each _page.items}}' +
Expand Down
2 changes: 1 addition & 1 deletion test/dom/bindings.mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var expect = require('chai').expect;
var domTestRunner = require('../../src/test-utils/domTestRunner');

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

describe('bracket dependencies', function() {
it('bracket inner dependency change', function() {
Expand Down
27 changes: 14 additions & 13 deletions test/dom/components.browser.mocha.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
var expect = require('chai').expect;
var templates = require('../../src/templates').templates;
var derby = require('./util').derby;
var domTestRunner = require('../../src/test-utils/domTestRunner');

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

describe('destroy', function() {
it('emits a "destroy" event when the component is removed from the DOM', function(done) {
var app = derby.createApp();
const { app } = runner.createHarness();
var page = app.createPage();
app.views.register('Body',
'{{unless _page.hide}}' +
Expand All @@ -26,7 +27,7 @@ describe('components', function() {
});

it('emits an event declared in the template with `on-destroy`', function(done) {
var app = derby.createApp();
const { app } = runner.createHarness();
var page = app.createPage();
app.views.register('Body',
'{{unless _page.hide}}' +
Expand All @@ -44,7 +45,7 @@ describe('components', function() {
});

it('sets `this.isDestroyed` property to true after a component has been fully destroyed', function() {
var app = derby.createApp();
const { app } = runner.createHarness();
var page = app.createPage();
app.views.register('Body',
'{{unless _page.hide}}' +
Expand All @@ -64,7 +65,7 @@ describe('components', function() {

describe('bind', function() {
it('calls a function with `this` being the component and passed in arguments', function() {
var app = derby.createApp();
const { app } = runner.createHarness();
var page = app.createPage();
app.views.register('Body', '<view is="box"></view>');
app.views.register('box', '<div>{{area}}</div>');
Expand Down Expand Up @@ -93,7 +94,7 @@ describe('components', function() {
options = options || {};

it('calls a function once with `this` being the component', function(done) {
var app = derby.createApp();
const { app } = runner.createHarness();
var page = app.createPage();
app.views.register('Body', '<view is="box" as="box"></view>');
app.views.register('box', '<div></div>');
Expand All @@ -117,7 +118,7 @@ describe('components', function() {
});

it('resets and calls again', function(done) {
var app = derby.createApp();
const { app } = runner.createHarness();
var page = app.createPage();
app.views.register('Body', '<view is="box" as="box"></view>');
app.views.register('box', '<div></div>');
Expand Down Expand Up @@ -149,7 +150,7 @@ describe('components', function() {
});

it('calls with the most recent arguments', function(done) {
var app = derby.createApp();
const { app } = runner.createHarness();
var page = app.createPage();
app.views.register('Body', '<view is="box" as="box"></view>');
app.views.register('box', '<div></div>');
Expand Down Expand Up @@ -222,7 +223,7 @@ describe('components', function() {
});
});
it('debounceAsync does not apply arguments if callback has only one argument', function(done) {
var app = derby.createApp();
const { app } = runner.createHarness();
var page = app.createPage();
app.views.register('Body', '<view is="box" as="box"></view>');
app.views.register('box', '<div></div>');
Expand All @@ -245,7 +246,7 @@ describe('components', function() {
page.box.update('a', 1);
});
it('debounceAsync debounces until the async call completes', function(done) {
var app = derby.createApp();
const { app } = runner.createHarness();
app.views.register('Body', '<view is="box"></view>');
app.views.register('box', '<div></div>');
var calls = 0;
Expand Down Expand Up @@ -279,7 +280,7 @@ describe('components', function() {
app.component('box', Box);
});
it('throttle calls no more frequently than delay', function(done) {
var app = derby.createApp();
const { app } = runner.createHarness();
app.views.register('Body', '<view is="box"></view>');
app.views.register('box', '<div></div>');
var delay = 10;
Expand Down Expand Up @@ -319,7 +320,7 @@ describe('components', function() {

describe('dependencies', function() {
it('gets dependencies rendered inside of components', function() {
var app = derby.createApp();
const { app } = runner.createHarness();
var page = app.createPage();
app.views.register('Body',
'<view is="box" title="{{_page.title}}, friend">' +
Expand All @@ -345,7 +346,7 @@ describe('components', function() {
});

it('does not return dependencies for local paths within components', function() {
var app = derby.createApp();
const { app } = runner.createHarness();
var page = app.createPage();
app.views.register('Body',
'<view is="box" title="{{_page.title}}"></view>'
Expand Down
10 changes: 6 additions & 4 deletions test/dom/dom-events.mocha.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
var expect = require('chai').expect;
var derby = require('./util').derby;
var domTestRunner = require('../../src/test-utils/domTestRunner');

describe('DOM events', function() {
const runner = domTestRunner.install();

it('HTML element markup custom `create` event', function() {
var app = derby.createApp();
const { app } = runner.createHarness();
app.views.register('Body',
'<div on-create="createDiv($element)">' +
'<span on-create="createSpan($element)"></span>' +
Expand All @@ -24,7 +26,7 @@ describe('DOM events', function() {
});

it('HTML element markup custom `destroy` event', function() {
var app = derby.createApp();
const { app } = runner.createHarness();
app.views.register('Body',
'<div>' +
'{{unless _page.hide}}' +
Expand All @@ -47,7 +49,7 @@ describe('DOM events', function() {
});

it('dom.on custom `destroy` event', function() {
var app = derby.createApp();
const { app } = runner.createHarness();
app.views.register('Body',
'<div>' +
'{{unless _page.hide}}' +
Expand Down

0 comments on commit b293fc7

Please sign in to comment.