mirror of https://github.com/sveltejs/svelte
Merge pull request #354 from taylorzane/api-create-component
API to create and return a component constructorpull/357/head
commit
415aed70e7
@ -0,0 +1,40 @@
|
||||
import deindent from '../src/utils/deindent.js';
|
||||
import assert from 'assert';
|
||||
import { svelte } from './helpers.js';
|
||||
|
||||
describe( 'create', () => {
|
||||
it( 'should return a component constructor', () => {
|
||||
const source = deindent`
|
||||
<div>{{prop}}</div>
|
||||
`;
|
||||
|
||||
const component = svelte.create( source );
|
||||
assert( component instanceof Function );
|
||||
});
|
||||
|
||||
it( 'should throw error when source is invalid ', done => {
|
||||
const source = deindent`
|
||||
<div>{{prop}</div>
|
||||
`;
|
||||
|
||||
const component = svelte.create( source, {
|
||||
onerror: () => {
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
assert.equal( component, undefined );
|
||||
});
|
||||
|
||||
it( 'should return undefined when source is invalid ', () => {
|
||||
const source = deindent`
|
||||
<div>{{prop}</div>
|
||||
`;
|
||||
|
||||
const component = svelte.create( source, {
|
||||
onerror: () => {}
|
||||
});
|
||||
|
||||
assert.equal( component, undefined );
|
||||
});
|
||||
});
|
Loading…
Reference in new issue