1/20
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Describe the high level steps to test a Visualforce page.
Create a PageReference to the Visualforce page
Pass the PageReference instance to Test.setCurrentPage()
Instantiate the controller for the Visualforce page.
If needed, instantiate an extension fr the page by passing the controller variable as a parameter to the extension constructor.
If needed, pass URLparametersto the controller using the following format: ApexPages.currentPage().getParameters().put('paramName','paramValue');
If a Visualforce controller redirects to another page, how can we check that the redirection worked as expected?
By calling the getUrl() method of the resulting PageReference variable
Describe the high level process of setting up and running jest tests for LWCs
1) Salesforce DX
Create a Salesforce DX project and install sfdx-lwc-jest and its dependencies (after installing Node.jsand npm). This Salesforce CLI command can be used: sf force lightning lwc test setup
2) Test files
Write Jest tests in local JavaScript files. The Salesforce CLI command, “sf force lightning lwc test create” can be used to create atest directory named “__tests__” and a boilerplate testfile within the directory. It is recommended that test files end in “.test.js”.
3) Run Jest commands
Run Jest tests fromVS Codeor the commandline using the command:“sf force lightning lwc test run”
What should a jest test file import?
The component to test and the createElement from “lwc”
How should a describe block be set up in a jest test?
Should be defined to create a test suite within the test file.
How should the DOM be handled in jest tests?
Since a single instance of jsdom, which is used to simulate a DOM environment in a browser, is shared across all the test cases in a test file, the DOM should be reset at the end of each unit test using the afterEach() method.
How should test blocks be set up in jest tests?
An it or test block should be defined to create a single functional unit test. Its first argument is a short description of the test and the second argument is a function containing the test. The expect statement can be used with a matcher like toBe for an assertion in the unit test.
How should instances be created in a jest test?
Inside the unit test, the imported createElement method can be used to create an instance of the component for testing. It should be appended to the body of the document using the appendChild() method
What command can be used to run jest tests?
Run
npm run test:unit
in the terminal
How can the shadow tree be accessed in a jest test?
When creating a unit test, the shadowRoot property of the element under test should be used to access the shadow tree. It can be used to select a particular element.
For example,
element.shadowRoot.querySelector(‘h1’)
can be used to select the <h1> element
How can asynchronous DOM updates such as property changes be tested in a jest test?
By using a Promise in the unit test
How can the wire service be tested?
Use the @salesforce/sfdx-lwc-jest test utility
What can be created to define Salesforce data expected by a component in a jest test?
A JSON file
What command can be used to run tests continuously during development?
The
npm run test:unit:watch
command
What has to be configured to view LWC debug info in the Chrome Dev Tools? And how can you view the debug info?
Debug Mode should be enabledfor the current user in Salesforce Setup
Custom formatters should be enabled in the Chrome DevTools settings
To view it, select Elements in Chrome DevTools and enter $0 to display debug info. @wired properties are also accessible in the debug info.
What is UTAM and describe aspects about it
UI Test Automation Model
UTAM is an open-source tool built by Salesforce which can be used to test any web page and is ideally suited for writing JavaScript or Java UI tests for Lightning web components.
In UTAM, page DOM elements that need to be tested are represented and referenced as JSON Page Objects. UTAM compiles each JSON Page Object into JavaScript, for example, which contain properties and methods which can then be used in writing the tests.
UTAM does not include a test runner but can be integrated with any testing automation framework. Currently, UTAM supports WebdriverIO for JavaScript tests and Selenium for Java.
Is Javascript case sensitive?
Unlike Apex or SOQL, JavaScript is case-sensitive.
So comparing a variable name of status instead of Status could cause an error.
What is implicit conversion in JavaScript and what is the best way to deal with it?
In a situation where operands of different data types are used in a single expression, JavaScript automatically converts an “invalid” data type to a “valid” type. Although there is a system to JavaScript evaluation of the data types, it is best not to use implicit type coercion, to avoid confusion
To determine whether two variables are equal, it is best practice to use the strict comparison (===) operator. It will only return true if both the variable value and data type are the same.
The !== operator can be used to return true if both the value and the data type are not the same.
Provide an example of where using var causes an issue with variable scope and how it can be fixed.
let howOldAmI = function() {
var num = 16;
for (var num = 0; num < 3; num++){
// do something cool
}
console.log('I am ' + num + ' years old!');
}
howOldAmI();
This prints I am 3 years old, since var in the for loop “hoists” the num variable scope up a higher level.
Instead use let to declare the variable in the for loop and the code will print “I am 16 years old”
What frameworks can be used to test aura components?
Jest, UTAM, Jasmine, Mocha, Selenium, Webdriver IO