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

Fix bug registering component with static view.is prop but no view.file prop #627

Merged
merged 2 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 6 additions & 2 deletions src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,13 @@ export abstract class AppBase<T = object> extends EventEmitter {
this.addViews(viewSource, viewName);
view = this.views.find(viewName);

} else if (name) {
} else if (viewName) {
// Look for a previously registered view matching the component name.
view = this.views.find(viewName);

// If no match, register a new empty view, for backwards compatibility.
if (!view) {
view = this.views.register(viewName, '');
}
} else {
view = this.views.register(viewName, '');
}
Expand Down
4 changes: 2 additions & 2 deletions test/all/ComponentHarness.mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,6 @@ describe('ComponentHarness', function() {
});

it('gets overridden without error', function() {
function ConflictingClown() {}
ConflictingClown.view = {is: 'clown'};
function Clown() {}
Clown.view = {
is: 'clown',
Expand All @@ -277,6 +275,8 @@ describe('ComponentHarness', function() {
'</div>',
dependencies: [Clown]
};
function ConflictingClown() {}
ConflictingClown.view = {is: 'clown', source: '<index:>'};
var html = new ComponentHarness(
'<view is="box" />', Box, ConflictingClown
).renderHtml().html;
Expand Down
58 changes: 58 additions & 0 deletions test/dom/components.mocha.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>');
});
});
});
});
});
Loading