Skip to content

Commit

Permalink
Fixed logging in trace test
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate committed Jan 21, 2019
1 parent d5f8855 commit 19ec170
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
37 changes: 20 additions & 17 deletions test/base/trace.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use strict"

const mobx = require("../../src/mobx.ts")
const utils = require("../utils/test-utils")

test("trace", () => {
mobx._resetGlobalState()
Expand Down Expand Up @@ -58,23 +59,25 @@ test("trace", () => {
})

test("1850", () => {
const x = mobx.observable({
firstname: "Michel",
lastname: "Weststrate",
get fullname() {
/* test multi line comment
(run this unit test from VS code, to manually verify serialization)
*/
var res = this.firstname + " " + this.lastname
mobx.trace(this, "fullname", true)
return res
}
})
utils.supressConsole(() => {
const x = mobx.observable({
firstname: "Michel",
lastname: "Weststrate",
get fullname() {
/* test multi line comment
(run this unit test from VS code, to manually verify serialization)
*/
var res = this.firstname + " " + this.lastname
mobx.trace(this, "fullname", true)
return res
}
})

mobx.autorun(() => {
x.fullname
mobx.autorun(() => {
x.fullname
})
expect(() => {
x.firstname += "!"
}).not.toThrow("Unexpected identifier")
})
expect(() => {
x.firstname += "!"
}).not.toThrow("Unexpected identifier")
})
10 changes: 8 additions & 2 deletions test/utils/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,22 @@ export function consoleWarn(block, regex) {
}

export function supressConsole(block) {
const messages = []
const { warn, error } = console
Object.assign(console, {
warn() {},
error() {}
warn(e) {
messages.push("[warn] " + e)
},
error(e) {
messages.push("[error] " + e)
}
})
try {
block()
} finally {
Object.assign(console, { warn, error })
}
return messages
}

export function stripAdminFromDescriptors(snapshot) {
Expand Down

0 comments on commit 19ec170

Please sign in to comment.