Lupa API Reference / @pawel-up/lupa/testing / TestContext
Class: TestContext
Defined in: src/testing/test_context.ts:9
A fresh copy of test context is shared with all the tests. Note, this runs in the browser context.
Extends
default
Constructors
Constructor
new TestContext(
test):TestContext
Defined in: src/testing/test_context.ts:12
Parameters
test
Returns
TestContext
Overrides
Macroable.constructor
Properties
assert
assert:
Assert
Defined in: src/assert/index.ts:25
cleanup
cleanup: (
cleanupCallback) =>void
Defined in: src/testing/test_context.ts:10
Parameters
cleanupCallback
Returns
void
network
network:
Network
Defined in: src/network/index.ts:118
test
test:
Test
Defined in: src/testing/test_context.ts:12
Methods
getter()
staticgetter<T,K>(this,name,accumulator,singleton?):void
Defined in: node_modules/@poppinss/macroable/build/index.d.ts:112
Adds a getter property to the class prototype using Object.defineProperty. Getters are computed properties that are evaluated each time they are accessed, unless the singleton flag is enabled.
Type Parameters
T
T extends (...args) => any
K
K extends string | number | symbol
Parameters
this
T
name
K
The name of the getter property
accumulator
() => InstanceType<T>[K]
Function that computes and returns the property value
singleton?
boolean
If true, the getter value is cached after first access
Returns
void
Example
// Add a regular getter
MyClass.getter('timestamp', function() {
return Date.now()
})
// Add a singleton getter (cached after first access)
MyClass.getter('config', function() {
return loadConfig()
}, true)
const instance = new MyClass()
instance.timestamp // Computed each time
instance.config // Computed once, then cachedInherited from
Macroable.getter
instanceProperty()
staticinstanceProperty<T,K>(this,name,value):void
Defined in: node_modules/@poppinss/macroable/build/index.d.ts:83
Adds an instance property that will be assigned to each instance during construction. Unlike macros which are added to the prototype, instance properties are unique to each instance.
Type Parameters
T
T extends (...args) => any
K
K extends string | number | symbol
Parameters
this
T
name
K
The name of the property to add to instances
value
InstanceType<T>[K]
The value to assign to the property on each instance
Returns
void
Example
// Add an instance method
MyClass.instanceProperty('save', function() {
console.log('Saving...', this.id)
})
const { save } = new MyClass()
save()Inherited from
Macroable.instanceProperty
macro()
staticmacro<T,K>(this,name,value):void
Defined in: node_modules/@poppinss/macroable/build/index.d.ts:62
Adds a macro (property or method) to the class prototype. Macros are standard properties that get added to the class prototype, making them available on all instances of the class.
Type Parameters
T
T extends (...args) => any
K
K extends string | number | symbol
Parameters
this
T
name
K
The name of the property or method to add
value
InstanceType<T>[K]
The value to assign to the property or method
Returns
void
Example
// Add a property macro
MyClass.macro('version', '1.0.0')
// Add a method macro
MyClass.macro('greet', function() {
return 'Hello!'
})
const instance = new MyClass()
instance.version // "1.0.0"
instance.greet() // "Hello!"Inherited from
Macroable.macro