Skip to content

Commit

Permalink
test(packages/sui-pde): update broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andresz1 committed Oct 9, 2024
1 parent 4bf566f commit 068cd7e
Showing 1 changed file with 54 additions and 18 deletions.
72 changes: 54 additions & 18 deletions packages/sui-pde/test/common/useDecisionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,9 @@ describe('useDecision hook', () => {
ready: cb => cb(),
track: sinon.spy()
}

const addDecideListener = sinon.stub()
const removeNotificationListener = sinon.stub()

stubFactory = decide => {
stubFactory = ({decide, addDecideListener}) => {
// eslint-disable-next-line react/prop-types
wrapper = ({children}) => (
<PdeContext.Provider value={{features: [], pde: {decide, addDecideListener, removeNotificationListener}}}>
Expand All @@ -281,16 +279,28 @@ describe('useDecision hook', () => {
describe('when the second time returns the same value as the first time', () => {
beforeEach(() => {
const decide = sinon.stub()

decide.onCall(0).returns({
const addDecideListener = sinon.stub()
const decision = {
variationKey: 'variation',
enabled: true,
variables: {},
ruleKey: 'rule',
flagKey: 'flag',
userContext: {},
reasons: []
})
}

decide.onCall(0).returns(decision)
addDecideListener.onCall(0).callsFake(({onDecide}) =>
onDecide({
type: 'flag',
decisionInfo: {
...decision,
decisionEventDispatched: true
}
})
)

decide.onCall(1).returns({
variationKey: 'variation',
enabled: true,
Expand All @@ -300,8 +310,17 @@ describe('useDecision hook', () => {
userContext: {},
reasons: []
})
addDecideListener.onCall(1).callsFake(({onDecide}) =>
onDecide({
type: 'flag',
decisionInfo: {
...decision,
decisionEventDispatched: true
}
})
)

stubFactory(decide)
stubFactory({decide, addDecideListener})
})

it('should send only one experiment viewed event', () => {
Expand All @@ -318,27 +337,44 @@ describe('useDecision hook', () => {
describe('when the second time returns a different value as the first time', () => {
beforeEach(() => {
const decide = sinon.stub()

decide.onCall(0).returns({
const addDecideListener = sinon.stub()
const decision = {
variationKey: 'variation_a',
enabled: true,
variables: {},
ruleKey: 'rule',
flagKey: 'flag',
userContext: {},
reasons: []
})
}

decide.onCall(0).returns(decision)
addDecideListener.onCall(0).callsFake(({onDecide}) =>
onDecide({
type: 'flag',
decisionInfo: {
...decision,
decisionEventDispatched: true
}
})
)

decide.onCall(1).returns({
variationKey: 'variation_b',
enabled: true,
variables: {},
ruleKey: 'rule',
flagKey: 'flag',
userContext: {},
reasons: []
...decision,
variationKey: 'variation_b'
})
addDecideListener.onCall(1).callsFake(({onDecide}) =>
onDecide({
type: 'flag',
decisionInfo: {
...decision,
variationKey: 'variation_b',
decisionEventDispatched: true
}
})
)

stubFactory(decide)
stubFactory({decide, addDecideListener})
})

it('should send two experiment viewed events', () => {
Expand Down

0 comments on commit 068cd7e

Please sign in to comment.