diff --git a/test/generator/index.js b/test/generator/index.js index 2f647bec1a..2588129cca 100644 --- a/test/generator/index.js +++ b/test/generator/index.js @@ -96,6 +96,11 @@ describe( 'generate', () => { // Put the constructor on window for testing window.SvelteComponent = SvelteComponent; + const warnings = []; + window.console.warn = warning => { + warnings.push( warning ); + }; + const target = window.document.querySelector( 'main' ); const component = new SvelteComponent({ @@ -108,6 +113,13 @@ describe( 'generate', () => { throw new Error( 'Expected a runtime error' ); } + if ( config.warnings ) { + assert.deepEqual( warnings, config.warnings ); + } else if ( warnings.length ) { + unintendedError = true; + throw new Error( 'Received unexpected warnings' ); + } + if ( config.html ) { assert.htmlEqual( target.innerHTML, config.html ); } diff --git a/test/generator/samples/dev-warning-bad-observe-arguments/_config.js b/test/generator/samples/dev-warning-bad-observe-arguments/_config.js new file mode 100644 index 0000000000..883b53062b --- /dev/null +++ b/test/generator/samples/dev-warning-bad-observe-arguments/_config.js @@ -0,0 +1,7 @@ +export default { + dev: true, + + error ( assert, err ) { + assert.equal( err.message, `The fisrt argument to component.observe(...) must be the name of a top-level property, i.e. 'nested' rather than 'nested.data'` ); + } +}; \ No newline at end of file diff --git a/test/generator/samples/dev-warning-bad-observe-arguments/main.html b/test/generator/samples/dev-warning-bad-observe-arguments/main.html new file mode 100644 index 0000000000..e15ae99fa4 --- /dev/null +++ b/test/generator/samples/dev-warning-bad-observe-arguments/main.html @@ -0,0 +1,9 @@ + \ No newline at end of file diff --git a/test/generator/samples/dev-warning-destroy-not-teardown/_config.js b/test/generator/samples/dev-warning-destroy-not-teardown/_config.js new file mode 100644 index 0000000000..fd8577de54 --- /dev/null +++ b/test/generator/samples/dev-warning-destroy-not-teardown/_config.js @@ -0,0 +1,7 @@ +export default { + dev: true, + + warnings: [ + `Use component.on('destroy', ...) instead of component.on('teardown', ...) which has been deprecated` + ] +}; \ No newline at end of file diff --git a/test/generator/samples/dev-warning-destroy-not-teardown/main.html b/test/generator/samples/dev-warning-destroy-not-teardown/main.html new file mode 100644 index 0000000000..22c2e9c287 --- /dev/null +++ b/test/generator/samples/dev-warning-destroy-not-teardown/main.html @@ -0,0 +1,9 @@ + \ No newline at end of file