Skip to content

Conversation

@NaamuKim
Copy link

What I do

Added tests with the toHaveLocalStorageItem function

Why this function is needed

before

const tokenExists = await browser.execute(() => {
    return localStorage.getItem('authToken') !== null
})
expect(tokenExists).toBe(true)

const tokenValue = await browser.execute(() => {
    return localStorage.getItem('authToken')
})
expect(tokenValue).toMatch(/^[A-Za-z0-9-_]+\./)

after

await expect(browser).toHaveLocalStorageItem('authToken')
await expect(browser).toHaveLocalStorageItem('authToken', /^[A-Za-z0-9-_]+\./)

If you need anything else, let me know and I'll get it implemented quickly.
If this API is okay, I'll also add a PR for Session storage.

@NaamuKim NaamuKim changed the title Feature/to have local storage item feat(expect-webdriverio): add toHaveLocalStorageItem matcher Jul 30, 2025
Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution and sorry for the delayed review. One request, can we ipdate the API docs: https://github.com/webdriverio/expect-webdriverio/blob/main/docs/API.md

@NaamuKim NaamuKim force-pushed the feature/toHaveLocalStorageItem branch from 7589af9 to 17b882d Compare November 25, 2025 12:42
@NaamuKim
Copy link
Author

Thanks for your review!
I updated docs in this commit17b882d

@christian-bromann
Copy link
Member

@NaamuKim mhm 🤔 seems like some tests are failing:

Error: src/matchers/browser/toHaveLocalStorageItem.ts(14,9): error TS2322: Type '"toHaveLocalStorageItem"' is not assignable to type 'keyof Matchers<void, unknown>'.
Error: src/matchers/browser/toHaveLocalStorageItem.ts(48,9): error TS2322: Type '"toHaveLocalStorageItem"' is not assignable to type 'keyof Matchers<void, unknown>'.

@NaamuKim
Copy link
Author

@christian-bromann I added types to matchers, can you rerun the tests?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants