Chapter 7: Share Your Story
Overview
Coming soon…
Training
Pre-requisites
Concepts Covered in This Chapter
Tools Used in This Chapter
Commands Used in This Chapter
Assertions
assert.is.true- Validates that a condition is true.
assert.is.equal- Checks if two values are equal.
assert.is.deep.equal- Verifies that complex or nested objects are deeply equal.
assert.does.throw.async- Asserts that an asynchronous operation throws an error.
assert.error.code- Verifies that a thrown error contains the expected code.
assert.card.renders.button- Confirms that a specific button is rendered within a card.
assert.action.redirects- Verifies that an action (e.g., button click) triggers a redirect.
assert.is.truthy- Ensures that a given value is truthy (not null or undefined).
Event Handling
eventFaker.fake.getStory- Fakes the
get.storyevent for test purposes.
- Fakes the
eventFaker.on- Sets up a listener for testing emitted events.
eventFaker.make.throw- Simulates error-throwing events during testing.
client.emit- Emits a specified event to the backend.
client.emit.and.flatten.responses- Emits an event and flattens the response for easier access.
View Controller Lifecycle
public async load- Main lifecycle method used to initialize the SkillView with options and routers.
this.router.redirect- Redirects to a specified view.
get.is.login.required- Returns whether the user must be logged in to view the SkillView.
View Controller and Form Management
formVC.get.values- Retrieves values from a form.
formVC.render- Renders a form based on a schema.
this.load- Used to invoke the load method manually during tests.
this.router- Accesses the router for view navigation.
SkillView Setup and Configuration
this.views.setController- Overrides the controller used by a view for testing purposes.
controller.Factory- Creates a new view controller instance.
this.views.render- Renders the current view controller and returns the model.
spyView.getCardVC- Returns the internal card view controller for assertions in tests.
Schemas and Events
build.schema- Used to define fields and structure for events or forms.
sync.events- Syncs event configuration across the project.
sync.permissions- Syncs permission definitions and fixes typing errors in tests.
sync.errors- Updates and rebuilds error types across the app.
generate.id- Generates unique identifiers for fake data or test payloads.
Error Handling
SpruceError- Used to throw platform-specific custom errors.
FamilyMemberNotFound / StoryNotFound- Examples of custom error codes used in tests.
Test Utilities
test.protected.static.async- Defines reusable protected test cases with async logic.
await this.load()- Manually triggers the load method with parameters in a test.
testRouter.setShouldThrowWhenRedirectingToBadSkillViewController(false)- Disables redirect validation when testing external skill redirects.
Sharing and Routing
buildRouteToCreateInvite- Generates a redirect path to the invite skill with parameters.
@sprucelabs/spruce-invite-utils- External utility library used to help construct valid invite URLs.
