Skip to content

Commit

Permalink
Cleaned up / fine tuned tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate committed Nov 6, 2018
1 parent 8b1c5ec commit 3d05926
Showing 1 changed file with 5 additions and 50 deletions.
55 changes: 5 additions & 50 deletions test/base/observables.js
Original file line number Diff line number Diff line change
Expand Up @@ -1925,22 +1925,7 @@ test("keeping computed properties alive runs on first access", () => {
}
)

expect(x.y).toBe(2) // perform calculation on access
expect(calcs).toBe(1)
})

test("(for objects) keeping computed properties alive runs on first access", () => {
let calcs = 0
class Foo {
@observable x = 1
@computed({ keepAlive: true })
get y() {
calcs++
return this.x * 2
}
}
const x = new Foo()

expect(calcs).toBe(0)
expect(x.y).toBe(2) // perform calculation on access
expect(calcs).toBe(1)
})
Expand All @@ -1965,23 +1950,6 @@ test("keeping computed properties alive caches values on subsequent accesses", (
expect(calcs).toBe(1) // only one calculation: cached!
})

test("(for objects) keeping computed properties alive caches values on subsequent accesses", () => {
let calcs = 0
class Foo {
@observable x = 1
@computed({ keepAlive: true })
get y() {
calcs++
return this.x * 2
}
}
const x = new Foo()

expect(x.y).toBe(2) // first access: do calculation
expect(x.y).toBe(2) // second access: use cached value, no calculation
expect(calcs).toBe(1) // only one calculation: cached!
})

test("keeping computed properties alive does not recalculate when dirty", () => {
let calcs = 0
const x = observable(
Expand All @@ -1998,24 +1966,7 @@ test("keeping computed properties alive does not recalculate when dirty", () =>
)

expect(x.y).toBe(2) // first access: do calculation
x.x = 3 // mark as dirty: no calculation
expect(calcs).toBe(1)
expect(x.y).toBe(6)
})

test("(for objects) keeping computed properties alive does not recalculate when dirty", () => {
let calcs = 0
class Foo {
@observable x = 1
@computed({ keepAlive: true })
get y() {
calcs++
return this.x * 2
}
}
const x = new Foo()

expect(x.y).toBe(2) // first access: do calculation
x.x = 3 // mark as dirty: no calculation
expect(calcs).toBe(1)
expect(x.y).toBe(6)
Expand All @@ -2037,7 +1988,9 @@ test("keeping computed properties alive recalculates when accessing it dirty", (
)

expect(x.y).toBe(2) // first access: do calculation
expect(calcs).toBe(1)
x.x = 3 // mark as dirty: no calculation
expect(calcs).toBe(1)
expect(x.y).toBe(6) // second access: do calculation because it is dirty
expect(calcs).toBe(2)
})
Expand All @@ -2055,7 +2008,9 @@ test("(for objects) keeping computed properties alive recalculates when accessin
const x = new Foo()

expect(x.y).toBe(2) // first access: do calculation
expect(calcs).toBe(1)
x.x = 3 // mark as dirty: no calculation
expect(calcs).toBe(1)
expect(x.y).toBe(6) // second access: do calculation because it is dirty
expect(calcs).toBe(2)
})
Expand Down

0 comments on commit 3d05926

Please sign in to comment.