-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(jest-transformer): update @salesforce/apex transform (#924)
* wip: fix @salesforce/apex import * wip: refreshApex to resolved promise + tests * wip: cleanup * wip: different Object for each Apex import * wip: move schema specific logic to schema transform * Update packages/@lwc/jest-transformer/src/test/modules/example/apex/apex.js Co-Authored-By: trevor-bliss <[email protected]> * wip: update tests * Apply suggestions from code review Co-Authored-By: trevor-bliss <[email protected]> * wip: remove dead code
- Loading branch information
Trevor
authored
Jan 8, 2019
1 parent
6e2817f
commit a3d6af5
Showing
8 changed files
with
320 additions
and
82 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
packages/@lwc/jest-transformer/src/test/modules/example/apex/__tests__/apex.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (c) 2018, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: MIT | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT | ||
*/ | ||
import { createElement } from 'lwc'; | ||
import Apex from 'example/apex'; | ||
|
||
afterEach(() => { | ||
while (document.body.firstChild) { | ||
document.body.removeChild(document.body.firstChild); | ||
} | ||
}); | ||
|
||
describe('example-apex', () => { | ||
describe('importing @salesforce/apex', () => { | ||
it('returns a Promise that resolves for the default import', () => { | ||
const element = createElement('example-apex', { is: Apex }); | ||
document.body.appendChild(element); | ||
const apexCall = element.callDefaultImport(); | ||
return apexCall.then((ret) => { | ||
expect(ret).toBe('from test'); | ||
}) | ||
}); | ||
|
||
it('returns a Promise that resolves for a second imported Apex method', () => { | ||
const element = createElement('example-apex', { is: Apex }); | ||
document.body.appendChild(element); | ||
const apexCall = element.callAnotherDefaultImport(); | ||
return apexCall.then((ret) => { | ||
expect(ret).toBe('from test'); | ||
}) | ||
}); | ||
|
||
it('returns a Promise that resolves for the refreshApex named import', () => { | ||
const element = createElement('example-apex', { is: Apex }); | ||
document.body.appendChild(element); | ||
const refreshApex = element.callRefreshApex(); | ||
return refreshApex.then((ret) => { | ||
expect(ret).toBe('from test'); | ||
}); | ||
}); | ||
}); | ||
}); |
30 changes: 30 additions & 0 deletions
30
...es/@lwc/jest-transformer/src/test/modules/example/apex/__tests__/apexWithJestMock.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (c) 2018, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: MIT | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT | ||
*/ | ||
import { createElement } from 'lwc'; | ||
import Apex from 'example/apex'; | ||
import { getSObjectValue } from '@salesforce/apex'; | ||
|
||
jest.mock('@salesforce/apex', () => { | ||
return { | ||
getSObjectValue: jest.fn(), | ||
} | ||
}, { virtual: true }); | ||
|
||
afterEach(() => { | ||
while (document.body.firstChild) { | ||
document.body.removeChild(document.body.firstChild); | ||
} | ||
}); | ||
|
||
describe('example-apex', () => { | ||
it('allows per-test mocking of @salesforce/apex.getSObjectValue', () => { | ||
const element = createElement('example-apex', { is: Apex }); | ||
document.body.appendChild(element); | ||
element.callGetSObjectValue(); | ||
expect(getSObjectValue).toHaveBeenCalledWith('from test'); | ||
}); | ||
}); |
7 changes: 7 additions & 0 deletions
7
packages/@lwc/jest-transformer/src/test/modules/example/apex/apex.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<!-- | ||
Copyright (c) 2018, salesforce.com, inc. | ||
All rights reserved. | ||
SPDX-License-Identifier: MIT | ||
For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT | ||
--> | ||
<template></template> |
39 changes: 39 additions & 0 deletions
39
packages/@lwc/jest-transformer/src/test/modules/example/apex/apex.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (c) 2018, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: MIT | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT | ||
*/ | ||
import { LightningElement, api } from 'lwc'; | ||
|
||
import ApexMethod from '@salesforce/apex/FooClass.FooMethod'; | ||
import AnotherApexMethod from '@salesforce/apex/Namespace.BarClass.BarMethod'; | ||
import { refreshApex, getSObjectValue } from '@salesforce/apex'; | ||
|
||
export default class Apex extends LightningElement { | ||
@api | ||
callDefaultImport() { | ||
return ApexMethod().then(() => { | ||
return 'from test'; | ||
}); | ||
} | ||
|
||
@api | ||
callAnotherDefaultImport() { | ||
return AnotherApexMethod().then(() => { | ||
return 'from test'; | ||
}); | ||
} | ||
|
||
@api | ||
callRefreshApex() { | ||
return refreshApex().then(() => { | ||
return 'from test'; | ||
}); | ||
} | ||
|
||
@api | ||
callGetSObjectValue() { | ||
getSObjectValue('from test'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.