This module will discuss the official testing suite for Ecma262 titled Test262. You will learn how to write tests for a proposal.
The goal of Test262 is to provide test material that covers every observable behavior specified in the ECMA-414 Standards Suite. It is the largest testing suite available for EcmaScript to date.
Using a shared testing suite has a lot of advantages. It allows the developers to see what engine is most compliant with the specification, what features are supported and what is currently unsupported.
As stated in Module 4, test262 has a website where the compliance of each engine can be viewed.
The official guidelines for contributing to Test262 state that an acceptable test is the following:
Any test that exercises observable grammar or semantics, originating with citable, normative text in the latest draft of the ECMAScript Language Specification, the ECMAScript Internationalization API Specification, the The JSON Data Interchange Syntax, a Stage 3 proposal or a Pull Request which makes a normative change to any of those specifications.
This states we can write tests for any observable grammar or semantic that originates from our specification (ECMAScript Language Specification). This is what we will be doing in this module.
In order to fully test our implementation, we have to test every "testable" line in the specification.
A "testable" line is when the behavior of the specification is observable to the user with a specific input. An example of a easily "testable" line in the specification is step 3:
3. If IsCallable(callbackfn) is false, throw a TypeError exception.
The test for this line of the specification should look something like this:
assert.throws(TypeError, function() {
[].group(null)
}, "null callback throws TypeError");
The assert
object is part of the Test262 suite, in this usecase we assert that [].group(null)
throws and error.
All the different functions on the assert object can be found in CONTRIBUTING.md in the official test262 github repository.
View all lines in the specification of Array grouping proposal. What parts of the specification are "testable"?
Write down what lines are testable and compare them with the document provided [here](LINK TO Solution!)
All new functions added to JavaScript have to use the correct properties. That means setting the following properties correctly: length
, name
. Each of these properties have accessor descriptors that has to be set correctly.
Examples of accessor descriptors which have to be set:
Enumerable
: An enumerable property will show up in enumeration of the object.
Writable
: If true, the property can be changed with an assignment operator (=)
More about properties and their accessor descriptors can be found here
View the tests of the feature Array.prototype.filter
to see an example of how these can be tested.
Your task is to write tests for 3-4 of the lines you specified in task 8.2.1.
The tests should ensure that both groupBy
and groupByToMap
adhere to the specification
When you have implemented your tests, compare them to the official tests in Test262 for this proposal.