From 0ea6a190b6f9a983818d8b112cb21f3150ed92fb Mon Sep 17 00:00:00 2001 From: soulofmischief Date: Sun, 22 Sep 2019 02:35:07 -0500 Subject: [PATCH] Fix assertion descriptions (#2405) * Fix assertion descriptions Move return statement to the end of define() * ospec: Fix assertion definitions * Fix typo in assertion * Add test for descriptions being returned on fail * Reference result instead of self in returned description method * Fix style errors --- docs/change-log.md | 1 + ospec/ospec.js | 5 ++++- ospec/tests/test-ospec.js | 20 +++++++++++++++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/docs/change-log.md b/docs/change-log.md index a2e22e01..d508d23b 100644 --- a/docs/change-log.md +++ b/docs/change-log.md @@ -123,6 +123,7 @@ _2019-07-24_ #### Bug fixes - API: `m.route.set()` causes all mount points to be redrawn ([#1592](https://github.com/MithrilJS/mithril.js/pull/1592)) +- ospec: Fix assertion definitions breaking on comparison failure - render/attrs: Using style objects in hyperscript calls will now properly diff style properties from one render to another as opposed to re-writing all element style properties every render. - render/attrs All vnodes attributes are properly removed when absent or set to `null` or `undefined` [#1804](https://github.com/MithrilJS/mithril.js/issues/1804) [#2082](https://github.com/MithrilJS/mithril.js/issues/2082) ([#1865](https://github.com/MithrilJS/mithril.js/pull/1865), [#2130](https://github.com/MithrilJS/mithril.js/pull/2130)) - render/core: Render state correctly on select change event [#1916](https://github.com/MithrilJS/mithril.js/issues/1916) ([#1918](https://github.com/MithrilJS/mithril.js/pull/1918) [@robinchew](https://github.com/robinchew), [#2052](https://github.com/MithrilJS/mithril.js/pull/2052)) diff --git a/ospec/ospec.js b/ospec/ospec.js index 7b63b5b5..854cbefb 100644 --- a/ospec/ospec.js +++ b/ospec/ospec.js @@ -291,8 +291,11 @@ else window.o = m() var message = serialize(self.value) + "\n " + verb + "\n" + serialize(value) if (compare(self.value, value)) succeed(self, message) else fail(self, message) + var result = results[self.i] return function(message) { - if (!self.pass) self.message = message + "\n\n" + self.message + if (!result.pass) { + result.message = message + "\n\n" + result.message + } } } } diff --git a/ospec/tests/test-ospec.js b/ospec/tests/test-ospec.js index 5e92d770..060bc5a5 100644 --- a/ospec/tests/test-ospec.js +++ b/ospec/tests/test-ospec.js @@ -299,7 +299,7 @@ o.spec("ospec", function() { }) }) - o.spec("throwing in test context is recoreded as a failure", function() { + o.spec("throwing in test context is recorded as a failure", function() { var oo o.beforeEach(function(){oo = o.new()}) o.afterEach(function() { @@ -659,6 +659,24 @@ o.spec("ospec", function() { }) }) }) + + o.spec("descriptions", function() { + o("description returned on failure", function(done) { + var oo = o.new() + oo("no description", function() { + oo(1).equals(2) + }) + oo("description", function() { + oo(1).equals(2)("howdy") + }) + oo.run(function(results) { + o(results.length).equals(2) + o(results[1].message).equals(`howdy\n\n${results[0].message}`) + o(results[1].pass).equals(false) + done() + }) + }) + }) }) o.spec("the done parser", function() { o("accepts non-English names", function() {