Skip to content

Commit

Permalink
Fix bug registering component with static view.is prop but no `view…
Browse files Browse the repository at this point in the history
….file` prop
  • Loading branch information
ericyhwang committed Jan 30, 2024
1 parent 8eedad2 commit 2449b82
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export abstract class AppBase<T = object> extends EventEmitter {
this.addViews(viewSource, viewName);
view = this.views.find(viewName);

} else if (name) {
} else if (viewName) {
view = this.views.find(viewName);

} else {
Expand Down
58 changes: 58 additions & 0 deletions test/dom/components.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
var expect = require('chai').expect;
var pathLib = require('node:path');
var domTestRunner = require('../../test-utils/domTestRunner');

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

describe('app.component registration', function() {
describe('passing just component class', function() {
describe('with static view prop', function() {
it('external view file', function() {
var harness = runner.createHarness();

function SimpleBox() {}
SimpleBox.view = {
is: 'simple-box',
// Static `view.file` property, defining path of view file
file: pathLib.resolve(__dirname, '../fixtures/simple-box')
};
harness.app.component(SimpleBox);

harness.setup('<view is="simple-box"/>');
expect(harness.renderHtml().html).to.equal('<div class="simple-box"></div>');
});

it('inlined view.source', function() {
var harness = runner.createHarness();

function SimpleBox() {}
SimpleBox.view = {
is: 'simple-box',
source: '<index:><div>Inlined source</div>'
};
harness.app.component(SimpleBox);

harness.setup('<view is="simple-box"/>');
expect(harness.renderHtml().html).to.equal('<div>Inlined source</div>');
});

it('inferred view file from view name', function() {
var harness = runner.createHarness();

// Pre-load view with same name as the component's static `view.is`
harness.app.loadViews(pathLib.resolve(__dirname, '../fixtures/simple-box'), 'simple-box');

function SimpleBox() {}
SimpleBox.view = {
is: 'simple-box'
};
harness.app.component(SimpleBox);

harness.setup('<view is="simple-box"/>');
expect(harness.renderHtml().html).to.equal('<div class="simple-box"></div>');
});
});
});
});
});

0 comments on commit 2449b82

Please sign in to comment.