Mailbox Functions
The mailbox API allows us to have an internal message bus for our tests. The mailbox is a key value store in which each key can store an array of values. It acts as a Last in, first out (LIFO) stack, so the last message that was posted to the mailbox will be popped the first.
You can use the following functions to interact with the Mailbox.
POST
This function will add a new value to the specified key.
//this function takes a string key and a value of any type as arguments
mailbox.post(key, value)
mailbox.post("key1", 33)
mailbox.post("key1", "Hello World")
mailbox.post("key1", {"Hello" : "World"})
POP
This function will pop the last data that was added to the key.
//this function takes a string key as an argument
mailbox.pop(key)
mailbox.pop("key1")
mailbox.pop("key1")
{ Hello: 'World' }
Hello World
COUNT
This function gives a count of the number of values with the current key.
//this function takes a string key as an argument
mailbox.count(key)
//Example
mailbox.post("key1", 33)
mailbox.post("key1", "Hello World")
mailbox.count("key1")
2
DUMP
This function dumps all the content inside the key instead of popping the values one by one.
It returns an array with all the values.
//this function takes a string key as an argument
mailbox.dump(key)
//Example
mailbox.post("key1", 33)
mailbox.post("key1", "Hello World")
mailbox.dump("key1")
[{ Hello: 'World' }, 'Hello World']
DELETE
This function deletes all the data for the mentioned key.
//this function takes a string key as an argument
mailbox.delete(key)
mailbox.delete("key1")
Last updated
Was this helpful?