Skip to content

feat(expect-webdriverio): add toHaveLocalStorageItem matcher#1900

Merged
christian-bromann merged 7 commits intowebdriverio:mainfrom
NaamuKim:feature/toHaveLocalStorageItem
Mar 7, 2026
Merged

feat(expect-webdriverio): add toHaveLocalStorageItem matcher#1900
christian-bromann merged 7 commits intowebdriverio:mainfrom
NaamuKim:feature/toHaveLocalStorageItem

Conversation

@NaamuKim
Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
Contributor Author

Thanks for your review!
I updated docs in this commit17b882d

@christian-bromann
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
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.

Great stuff, thanks a lot 👍

@christian-bromann
Copy link
Copy Markdown
Member

@NaamuKim it seems like there is still a valid test error:

 FAIL  test/index.test.ts > index
AssertionError: expected 42 to deeply equal 41

- Expected
+ Received

- 41
+ 42

 ❯ test/index.test.ts:8:27
      6|     expect(expectExport).toBeDefined()
      7|     expect(utils.compareText).toBeDefined()
      8|     expect(matchers.size).toEqual(41)
       |                           ^
      9| })
     10| 

@dprevost-LMI
Copy link
Copy Markdown
Contributor

@NaamuKim, do you want a hand with this one to finish it up?

@christian-bromann
Copy link
Copy Markdown
Member

@dprevost-LMI I suggest let's get this over the goal line

@NaamuKim
Copy link
Copy Markdown
Contributor Author

NaamuKim commented Feb 1, 2026

Sorry, I've been busy for a while. I've solved the test and fixed the crash, so please check it out. There's a lot of updated content. It looks good.

image

Copy link
Copy Markdown
Contributor

@dprevost-LMI dprevost-LMI left a comment

Choose a reason for hiding this comment

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

Nice matcher.
FYI: Following support of $$(), I'll adapt some code personally later on!
Thanks for the contribution!

@christian-bromann christian-bromann merged commit 4f8e9b5 into webdriverio:main Mar 7, 2026
3 checks passed
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.

3 participants