You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
All test helpers work with standard JavaScript object access syntax.
constAdventureLandTestHelpers=require('adventure-land-test-helpers');const{ mocks, stubs }=AdventureLandTestHelpers;letmonster=mocks.data.MockMonster;stubs.classic.is_monster(monster);// The "classic" stub will always return true.
Alternately, stubs may be injected into the global scope to mimic the game environment.
constAdventureLandTestHelpers=require('adventure-land-test-helpers');const{ injectIntoScope, stubs }=AdventureLandTestHelpers;injectIntoScope(stubs.random,this);is_monster();// The "random" stub will return true or false.
API
Inject into Scope
Path:AdventureLandTestHelpers.injectIntoScope
Description: Inject functions into the desired scope, useful for creating global stubs.
// Inject stubs into the global scope...constAdventureLandTestHelpers=require('adventure-land-test-helpers');const{ injectIntoScope, stubs }=AdventureLandTestHelpers;injectIntoScope(stubs.random,this);// ...then call one of the Adventure Land game functions.is_monster();
Mock Data
Path:AdventureLandTestHelpers.mocks.data
Description: Mock game data that can be useful when testing scripts.
Type
Path
Character
mocks.data.MockCharacter
Circle
mocks.data.MockCircle
ItemStats
mocks.data.MockItemStats
Line
mocks.data.MockLine
Map
mocks.data.MockMap
Monster
mocks.data.MockMonster
Player
mocks.data.MockPlayer
Socket
mocks.data.MockSocket
Classic Stubs
Path:AdventureLandTestHelpers.stubs.classic
Description: Stubbed game runner functions
that return the same value every time when called.
Return Type
Return Value
*
true
Character, Monster, Player
MockCharacter
{ string: string }
{ abc: 'xyz' }
Boolean
true
Character
MockCharacter
Circle
MockCircle
ItemStats
MockItemStats
Line
MockLine
Map
MockMap
Monster
MockMonster
Number
42
Player
MockPlayer
Socket
MockSocket
undefined
undefined
Random Stubs
Path:AdventureLandTestHelpers.stubs.classic
Description: Stubbed game runner functions
that return a random possible value when called.