Skip to content

Commit 30b3aa1

Browse files
mcreinhardcopybara-github
authored andcommitted
refactor: add test environment function for defining the fake <gmp-map>
PiperOrigin-RevId: 550025104
1 parent 3b94419 commit 30b3aa1

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/place_picker/place_picker_test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

77
// import 'jasmine'; (google3-only)
8-
import '../testing/fake_gmp_components.js';
98

109
import {html, TemplateResult} from 'lit';
1110

@@ -68,6 +67,10 @@ const FAKE_PLACES_LIBRARY = {
6867
describe('PlacePicker', () => {
6968
const env = new Environment();
7069

70+
beforeAll(() => {
71+
env.defineFakeMapElement();
72+
});
73+
7174
async function prepareState(template?: TemplateResult) {
7275
const root =
7376
env.render(template ?? html`<gmpx-place-picker></gmpx-place-picker>`);

src/testing/environment.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
import {ReactiveElement, render as litRender, TemplateResult} from 'lit';
1010

1111
import {APILoader} from '../api_loader/api_loader.js';
12-
import {FAKE_GOOGLE_MAPS} from '../testing/fake_google_maps.js';
12+
13+
import {FakeMapElement} from './fake_gmp_components.js';
14+
import {FAKE_GOOGLE_MAPS} from './fake_google_maps.js';
1315

1416
declare global {
1517
module jasmine {
@@ -97,6 +99,11 @@ export class Environment {
9799
return root;
98100
}
99101

102+
defineFakeMapElement() {
103+
if (!customElements.get('gmp-map')) {
104+
customElements.define('gmp-map', FakeMapElement);
105+
}
106+
}
100107

101108
/**
102109
* Waits for all Lit `ReactiveElement` children of the given parent node to

src/testing/fake_gmp_components.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,13 @@
1919
*/
2020

2121
import {LitElement} from 'lit';
22-
import {customElement} from 'lit/decorators.js';
2322

2423
declare global {
2524
interface HTMLElementTagNameMap {
2625
'gmp-map': FakeMapElement;
2726
}
2827
}
2928

30-
@customElement('gmp-map')
3129
export class FakeMapElement extends LitElement {
3230
readonly innerMap = {} as google.maps.Map;
3331
}

0 commit comments

Comments
 (0)