First you have to understand what Stale Element Reference Error
is.
From Mozilla...
The stale element reference error is a WebDriver error that occurs because the referenced web element is no longer attached to the DOM. ... When an element is no longer attached to the DOM, i.e. it has been removed from the document or the document has changed, it is said to be stale
... meaning that when you first interacted with the element, it was tagged as present, but the next time that you intended to use that element it's already gone but is still tagged as present, leading to the error that you are now encountering.
In your code for example,
it('Add button should exist', async () => {
var add = $('[test-id="add"]');
browser.wait(EC.presenceOf(add), 10372);
// Code continues because the element 'add' is present.
expect(await add.isPresent()).toBeTruthy(); // Stale error is thrown here when the saved element 'add' is not present anymore.
});
To fix it, simply re-look for the element directly instead of referencing it from one instance.
it('Add button should exist', async () => {
browser.wait(EC.presenceOf($('[test-id="add"]')), 10372);
expect(await $('[test-id="add"]').isPresent()).toBeTruthy();
});
Even then, what you're doing here is like expect(true).toBeTruthy();
since the Expected Conditions have already passed for the presence of the element.