Skip to content

Commit e1929c5

Browse files
[FSSDK-11100] test fix
1 parent 7f74ca5 commit e1929c5

File tree

2 files changed

+7
-22
lines changed

2 files changed

+7
-22
lines changed

lib/core/audience_evaluator/index.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ describe('lib/core/audience_evaluator', () => {
209209
describe('integration with dependencies', () => {
210210
beforeEach(() => {
211211
vi.clearAllMocks();
212-
vi.spyOn(conditionTreeEvaluator, 'evaluate').mockImplementation(() => true);
213212
});
214213

215214
afterEach(() => {
@@ -306,7 +305,7 @@ describe('lib/core/audience_evaluator', () => {
306305
expect(mockCustomAttributeConditionEvaluator).toHaveBeenCalledTimes(1);
307306
expect(mockCustomAttributeConditionEvaluator).toHaveBeenCalledWith(iphoneUserAudience.conditions[1], user);
308307
expect(result).toBe(false);
309-
expect(2).toStrictEqual(mockLogger.debug.caller);
308+
expect(mockLogger.debug).toHaveBeenCalledTimes(2);
310309

311310
expect(mockLogger.debug).toHaveBeenCalledWith(
312311
EVALUATING_AUDIENCE,
@@ -333,7 +332,7 @@ describe('lib/core/audience_evaluator', () => {
333332
expect(mockCustomAttributeConditionEvaluator).toHaveBeenCalledTimes(1);
334333
expect(mockCustomAttributeConditionEvaluator).toHaveBeenCalledWith(iphoneUserAudience.conditions[1], user);
335334
expect(result).toBe(true);
336-
expect(2).toStrictEqual(mockLogger.debug.call.length);
335+
expect(mockLogger.debug).toHaveBeenCalledTimes(2)
337336
expect(mockLogger.debug).toHaveBeenCalledWith(
338337
EVALUATING_AUDIENCE,
339338
'1',
@@ -359,7 +358,7 @@ describe('lib/core/audience_evaluator', () => {
359358
expect(mockCustomAttributeConditionEvaluator).toHaveBeenCalledTimes(1);
360359
expect(mockCustomAttributeConditionEvaluator).toHaveBeenCalledWith(iphoneUserAudience.conditions[1], user);
361360
expect(result).toBe(false);
362-
expect(2).toStrictEqual(mockLogger.debug.call.length);
361+
expect(mockLogger.debug).toHaveBeenCalledTimes(2)
363362
expect(mockLogger.debug).toHaveBeenCalledWith(
364363
EVALUATING_AUDIENCE,
365364
'1',

lib/core/audience_evaluator/odp_segment_condition_evaluator/index.spec.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import { beforeEach, afterEach, describe, it, vi, expect } from 'vitest';
17-
16+
import { afterEach, describe, it, vi, expect } from 'vitest';
1817
import * as odpSegmentEvalutor from '.';
1918
import { UNKNOWN_MATCH_TYPE } from '../../../message/error_message';
2019
import { IOptimizelyUserContext } from '../../../optimizely_user_context';
2120
import { OptimizelyDecideOption, OptimizelyDecision } from '../../../shared_types';
21+
import { getMockLogger } from '../../../tests/mock/mock_logger';
2222

2323
const odpSegment1Condition = {
2424
"value": "odp-segment-1",
@@ -46,23 +46,10 @@ const getMockUserContext = (attributes?: unknown, segments?: string[]): IOptimiz
4646
}) as IOptimizelyUserContext;
4747

4848

49-
const createLogger = () => ({
50-
debug: () => {},
51-
info: () => {},
52-
warn: () => {},
53-
error: () => {},
54-
child: () => createLogger(),
55-
})
56-
5749
describe('lib/core/audience_evaluator/odp_segment_condition_evaluator', function() {
58-
const mockLogger = createLogger();
50+
const mockLogger = getMockLogger();
5951
const { evaluate } = odpSegmentEvalutor.getEvaluator(mockLogger);
6052

61-
beforeEach(function() {
62-
vi.fn(mockLogger.warn);
63-
vi.fn(mockLogger.error);
64-
});
65-
6653
afterEach(function() {
6754
vi.restoreAllMocks();
6855
});
@@ -82,7 +69,6 @@ describe('lib/core/audience_evaluator/odp_segment_condition_evaluator', function
8269
};
8370
expect(evaluate(invalidOdpMatchCondition, getMockUserContext({}, ['odp-segment-1']))).toBeNull();
8471
expect(mockLogger.warn).toHaveBeenCalledTimes(1);
85-
expect(mockLogger.warn.arguments[0][0]).toStrictEqual(UNKNOWN_MATCH_TYPE);
86-
expect(mockLogger.warn.arguments[0][1]).toStrictEqual(JSON.stringify(invalidOdpMatchCondition));
72+
expect(mockLogger.warn).toHaveBeenCalledWith(UNKNOWN_MATCH_TYPE, JSON.stringify(invalidOdpMatchCondition));
8773
});
8874
});

0 commit comments

Comments
 (0)