|
1 | 1 | import EventEmitter from "eventemitter3";
|
2 | 2 | import debounce from "debounce";
|
| 3 | +import invariant from "fbjs/lib/invariant"; |
3 | 4 | import {canUseDOM} from "fbjs/lib/ExecutionEnvironment";
|
4 | 5 | import Events from "./Events";
|
5 | 6 | import isInViewport from "./utils/isInViewport";
|
6 |
| -import {GPTMock} from "./utils/mockGPT"; |
7 | 7 |
|
8 | 8 | // based on https://developers.google.com/doubleclick-gpt/reference?hl=en
|
9 | 9 | export const pubadsAPI = [
|
@@ -44,7 +44,7 @@ export class AdManager extends EventEmitter {
|
44 | 44 | super(config);
|
45 | 45 |
|
46 | 46 | if (config.test) {
|
47 |
| - this.testMode = config.test; |
| 47 | + this.testMode = config; |
48 | 48 | }
|
49 | 49 | }
|
50 | 50 |
|
@@ -84,9 +84,17 @@ export class AdManager extends EventEmitter {
|
84 | 84 | if (process.env.NODE_ENV === "production") {
|
85 | 85 | return;
|
86 | 86 | }
|
87 |
| - this._googletag = new GPTMock(config); |
| 87 | + const {test, GPTMock} = config; |
88 | 88 | this._isLoaded = true;
|
89 |
| - this._testMode = !!config; |
| 89 | + this._testMode = !!test; |
| 90 | + |
| 91 | + if (test) { |
| 92 | + invariant( |
| 93 | + test && GPTMock, |
| 94 | + "Must provide GPTMock to enable testMode. config{GPTMock}" |
| 95 | + ); |
| 96 | + this._googletag = new GPTMock(config); |
| 97 | + } |
90 | 98 | }
|
91 | 99 |
|
92 | 100 | _processPubadsQueue() {
|
@@ -443,7 +451,7 @@ export class AdManager extends EventEmitter {
|
443 | 451 | reject(new Error("window.googletag is not available"));
|
444 | 452 | }
|
445 | 453 | };
|
446 |
| - if (window.googletag && googletag.apiReady) { |
| 454 | + if (window.googletag && window.googletag.apiReady) { |
447 | 455 | onLoad();
|
448 | 456 | } else {
|
449 | 457 | const script = document.createElement("script");
|
|
0 commit comments