diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..fe577258b --- /dev/null +++ b/.editorconfig @@ -0,0 +1,14 @@ +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +end_of_line = lf +insert_final_newline = true + +# Matches multiple files with brace expansion notation +# Set default charset +[*.{js,json,marko,yml}] +charset = utf-8 +indent_style = space +indent_size = 4 diff --git a/test/autotests/widgets-browser/state-watch-null-async/index.marko b/test/autotests/widgets-browser/state-watch-null-async/index.marko new file mode 100644 index 000000000..1d24f6716 --- /dev/null +++ b/test/autotests/widgets-browser/state-watch-null-async/index.marko @@ -0,0 +1,21 @@ +class { + onInput(input) { + this.state = { + error: null + }; + } + + submit() { + var self = this; + + setTimeout(function() { + self.state.error = 'FATAL ERROR'; + }, 50); + } +} + +
diff --git a/test/autotests/widgets-browser/state-watch-null-async/test.js b/test/autotests/widgets-browser/state-watch-null-async/test.js new file mode 100644 index 000000000..09b8e871f --- /dev/null +++ b/test/autotests/widgets-browser/state-watch-null-async/test.js @@ -0,0 +1,15 @@ +// see https://github.com/marko-js/marko/issues/556 +var expect = require('chai').expect; + +module.exports = function(helpers, done) { + var widget = helpers.mount(require('./index'), {}); + + expect(widget.el.innerHTML).to.not.contain('FATAL ERROR'); + + helpers.triggerEvent(widget.getEl(), 'submit'); + + setTimeout(function() { + expect(widget.el.innerHTML).to.contain('FATAL ERROR'); + done(); + }, 100); +}; diff --git a/test/util/BrowserHelpers.js b/test/util/BrowserHelpers.js index ba6ed6be7..4fd3b1602 100644 --- a/test/util/BrowserHelpers.js +++ b/test/util/BrowserHelpers.js @@ -8,6 +8,12 @@ function BrowserHelpers() { } BrowserHelpers.prototype = { + triggerEvent: function(el, type) { + var ev = document.createEvent("Event"); + ev.initEvent(type, true, true); + el.dispatchEvent(ev); + }, + triggerMouseEvent: function(el, type) { var ev = document.createEvent("MouseEvent"); ev.initMouseEvent( @@ -87,4 +93,4 @@ BrowserHelpers.prototype = { } }; -module.exports = BrowserHelpers; \ No newline at end of file +module.exports = BrowserHelpers;