Skip to content

Commit 1abab23

Browse files
committed
clean up tests
1 parent a198e0c commit 1abab23

File tree

1 file changed

+27
-33
lines changed

1 file changed

+27
-33
lines changed
Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {masterSelection} from '#3p/ampcontext-integration';
1+
import {IntegrationAmpContext, masterSelection} from '#3p/ampcontext-integration';
22

33
describes.fakeWin('#masterSelect', {}, (env) => {
44
it('should allow sharing between configured networks', () =>
@@ -11,54 +11,48 @@ describes.sandboxed('IntegrationAmpContext aliases', {}, (env) => {
1111
let context;
1212

1313
beforeEach(() => {
14-
// Create a minimal context object that implements the needed methods
15-
context = {
16-
master_: env.sandbox.stub().returns('master-window'),
17-
isMaster_: env.sandbox.stub().returns(true),
18-
computeInMasterFrame: env.sandbox.stub(),
19-
};
20-
21-
// Apply the getters from IntegrationAmpContext prototype
22-
Object.defineProperty(context, 'coordinator', {
23-
get() {
24-
return this.master_();
25-
},
26-
});
27-
Object.defineProperty(context, 'isCoordinator', {
28-
get() {
29-
return this.isMaster_();
30-
},
31-
});
32-
context.computeInCoordinatingFrame = function (global, taskId, work, cb) {
33-
return this.computeInMasterFrame(global, taskId, work, cb);
34-
};
14+
context = Object.create(IntegrationAmpContext.prototype);
15+
context.master_ = env.sandbox.stub().returns('test-master-window');
16+
context.isMaster_ = env.sandbox.stub().returns(true);
17+
context.computeInMasterFrame = env.sandbox.stub();
3518
});
3619

3720
it('should delegate coordinator to master', () => {
3821
const result = context.coordinator;
22+
3923
expect(context.master_).to.have.been.calledOnce;
40-
expect(result).to.equal('master-window');
24+
expect(result).to.equal('test-master-window');
4125
});
4226

4327
it('should delegate isCoordinator to isMaster', () => {
4428
const result = context.isCoordinator;
29+
4530
expect(context.isMaster_).to.have.been.calledOnce;
4631
expect(result).to.equal(true);
4732
});
4833

49-
it('should delegate computeInCoordinatingFrame to computeInMasterFrame', () => {
50-
const global = {test: 'global'};
34+
it('should execute computeInCoordinatingFrame method', () => {
35+
const masterWindow = {__ampMasterTasks: {}};
36+
const global = {
37+
context: {
38+
master: masterWindow,
39+
isMaster: true,
40+
},
41+
};
5142
const taskId = 'test-task';
52-
const work = () => {};
53-
const cb = () => {};
43+
let workCalled = false;
44+
const work = (done) => {
45+
workCalled = true;
46+
done('result');
47+
};
48+
let callbackResult;
49+
const cb = (result) => {
50+
callbackResult = result;
51+
};
5452

5553
context.computeInCoordinatingFrame(global, taskId, work, cb);
5654

57-
expect(context.computeInMasterFrame).to.have.been.calledOnceWith(
58-
global,
59-
taskId,
60-
work,
61-
cb
62-
);
55+
expect(workCalled).to.be.true;
56+
expect(callbackResult).to.equal('result');
6357
});
6458
});

0 commit comments

Comments
 (0)