|
| 1 | +import { module, test } from 'qunit'; |
| 2 | +import { setupRenderingTest } from 'ember-qunit'; |
| 3 | +import { render } from '@ember/test-helpers'; |
| 4 | +import hbs from 'htmlbars-inline-precompile'; |
| 5 | + |
| 6 | +module('Integration | Helpers | type-signature', function(hooks) { |
| 7 | + setupRenderingTest(hooks); |
| 8 | + |
| 9 | + test('renders a simple getter signature', async function(assert) { |
| 10 | + this.set('item', { |
| 11 | + name: 'foo', |
| 12 | + hasGetter: true, |
| 13 | + type: 'string' |
| 14 | + }); |
| 15 | + |
| 16 | + await render(hbs`{{type-signature item}}`); |
| 17 | + |
| 18 | + assert.equal(this.element.innerText, 'get foo: string'); |
| 19 | + }); |
| 20 | + |
| 21 | + test('renders a simple setter signature', async function(assert) { |
| 22 | + this.set('item', { |
| 23 | + name: 'foo', |
| 24 | + hasSetter: true, |
| 25 | + type: 'string' |
| 26 | + }); |
| 27 | + |
| 28 | + await render(hbs`{{type-signature item}}`); |
| 29 | + |
| 30 | + assert.equal(this.element.innerText, 'set foo: string'); |
| 31 | + }); |
| 32 | + |
| 33 | + test('renders a simple getter signature', async function(assert) { |
| 34 | + this.set('item', { |
| 35 | + name: 'foo', |
| 36 | + hasGetter: true, |
| 37 | + hasSetter: true, |
| 38 | + type: 'string' |
| 39 | + }); |
| 40 | + |
| 41 | + await render(hbs`{{type-signature item}}`); |
| 42 | + |
| 43 | + assert.equal(this.element.innerText, 'get/set foo: string'); |
| 44 | + }); |
| 45 | + |
| 46 | + test('renders a simple variable', async function(assert) { |
| 47 | + this.set('item', { name: 'foo', type: 'string' }); |
| 48 | + |
| 49 | + await render(hbs`{{type-signature item}}`); |
| 50 | + |
| 51 | + assert.equal(this.element.innerText, 'foo: string'); |
| 52 | + }); |
| 53 | + |
| 54 | + test('renders a simple function signature', async function(assert) { |
| 55 | + this.set('item', { name: 'foo', params: [], returns: { type: 'string' } }); |
| 56 | + |
| 57 | + await render(hbs`{{type-signature item}}`); |
| 58 | + |
| 59 | + assert.equal(this.element.innerText, 'foo(): string'); |
| 60 | + }); |
| 61 | + |
| 62 | + test('renders static and access modifiers', async function(assert) { |
| 63 | + this.set('item', { name: 'foo', type: 'string', isStatic: true, access: 'private' }); |
| 64 | + |
| 65 | + await render(hbs`{{type-signature item}}`); |
| 66 | + |
| 67 | + assert.equal(this.element.innerText, 'private static foo: string'); |
| 68 | + }); |
| 69 | + |
| 70 | + test('renders functions with optional and rest params', async function(assert) { |
| 71 | + this.set('item', { |
| 72 | + name: 'foo', |
| 73 | + params: [ |
| 74 | + { name: 'a', type: 'number' }, |
| 75 | + { name: 'b', type: 'string', isOptional: true }, |
| 76 | + { name: 'c', type: 'any[]', isRest: true } |
| 77 | + ] |
| 78 | + }); |
| 79 | + |
| 80 | + await render(hbs`{{type-signature item}}`); |
| 81 | + |
| 82 | + assert.equal(this.element.innerText, 'foo(a: number, b?: string, ...c: any[]): any'); |
| 83 | + }); |
| 84 | + |
| 85 | + test('renders functions with type params', async function(assert) { |
| 86 | + this.set('item', { |
| 87 | + name: 'foo', |
| 88 | + typeParams: ['T, U extends PromiseLike<T>'], |
| 89 | + params: [{ name: 'value', type: 'U' }], |
| 90 | + returns: { type: 'T' }, |
| 91 | + }); |
| 92 | + |
| 93 | + await render(hbs`{{type-signature item}}`); |
| 94 | + |
| 95 | + assert.equal(this.element.innerText, 'foo<T, U extends PromiseLike<T>>(value: U): T'); |
| 96 | + }); |
| 97 | + |
| 98 | + test('renders functions with multiple signatures', async function(assert) { |
| 99 | + this.set('item', { |
| 100 | + name: 'foo', |
| 101 | + signatures: [ |
| 102 | + { |
| 103 | + params: [], |
| 104 | + returns: { type: 'Promise<void>' } |
| 105 | + }, |
| 106 | + { |
| 107 | + typeParams: ['T'], |
| 108 | + params: [{ name: 'value', type: 'T' }], |
| 109 | + returns: { type: 'Promise<T>' } |
| 110 | + } |
| 111 | + ] |
| 112 | + }); |
| 113 | + |
| 114 | + await render(hbs`{{type-signature item}}`); |
| 115 | + |
| 116 | + assert.equal(this.element.innerText, 'foo(): Promise<void>\nfoo<T>(value: T): Promise<T>'); |
| 117 | + }); |
| 118 | +}); |
0 commit comments